Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9085425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:14:28+00:00 2026-06-16T21:14:28+00:00

I would like to take values that are calculated in IML to be used

  • 0

I would like to take values that are calculated in IML to be used in SAS’ printing functionality %PRNTINIT. This functionality is used to provide weekly reports from a database that can get updated.

I have some legacy code that uses proc sql to declare macro-type values that are called upon later, e.g.:

Declaring variables: tot1-tot4

*Get total number of subjects in each group in macro variable;
proc sort data = avg3; by description; run;
proc sql noprint;
select _freq_
into: tot1-:tot4
from avg3;
quit;

Calling variables tot1-tot4 for printing

%print(column = 1, style = bold, just = center, lines = bottom:none);
%print("(N= &tot1)", column = 2, just = center, lines = bottom:none);
%print("(N= &tot2)", column = 3, just = center, lines = bottom:none);
%print("(N= &tot3)", column = 4,  just = center, lines = bottom:none);
%print("(N= &tot4 )", column = 5,  just = center, lines = bottom:none);
%print(column = 6, just = center, lines = bottom:none);

I would like to be able to call values from IML similarly, if possible.


Example data:

data test ;
input age  type  gender $;
cards;
1 1 m
1 1 m
1 1 m
1 1 f
1 1 f
1 2 f
2 1 m
2 1 f
2 2 m
2 2 m
2 2 m
2 2 m
2 2 m
2 2 f
2 2 f
2 2 f
;




proc freq data = test;
tables type*age /  chisq norow nocol nopercent outexpect out=out1 ;
tables type*gender / chisq norow nocol nopercent outexpect out=out2 ;
run;


options missing=" ";

proc iml;

reset print; 

use out2;
read all var {count} into count;

type1 = count[1:2] ;
type2 = count[3:4] ;

tab = type1 || type2 ;

cols = tab[+,] ;
rows = tab[,+] ;
tot  = sum(tab) ;

perc = round(cols / tot, .01) ;

cell_perc = round(tab / (cols//cols) , .01) ;


expect = (rows * cols) / tot ;
chi_1 = sum((tab - expect)##2/expect) ;
p_chi_1 = 1-CDF('CHISQUARE',chi_1, ((ncol(tab)-1)*(nrow(tab)-1)));



print tab p_chi_1 perc cell_perc;



out_sex = tab || (. // p_chi_1);

print out_sex;

print out_sex[colname={"1","2"} 
              rowname={"f" "m" "p-value"}
              label="Table of Type by Gender"];




call symput(t1_sum, cols[1,1]) ;

%let t2_sum = put(cols[1,2]) ;
%let t1_per = perc[1,1] ;
%let t2_per = perc[1,2] ; 



%let t1_f = tab[1,1] ;
%let t1_m = tab[2,1] ;
%let t2_f = tab[1,2] ;
%let t2_m = tab[2,2] ;

%let t1_f_p = cell_perc[1,1] ;
%let t1_m_p = cell_perc[2,1] ;
%let t2_f_p = cell_perc[1,2] ;
%let t2_m_p = cell_perc[2,2] ;



%let p_val = p_chi_1 ;


*****  is it possible to list output values here for use in table building ???   ;
*  like:    %let t1_f = tab[1,1]
            %let t2_f = tab[2,1]   etc...  ;

quit;

So I would like to declare a print statement like the following:

%print( "(N=&tab[1,1], column = 1, just=center, lines = bottom:none);
%print( "(N=&tab[1,2], column = 2, just=center, lines = bottom:none);
etc...

Any help on this is greatly appreciated…


Update: Unable to extract declared macro values out of IML

I have been able to calculate the correct values and format the table successfully.

However, I am unable to extract the values for use in the print macro.

I have created some matrices and calculated values in IML, but when I try to declare macro variables for use later, the only thing that is returned is the literal value that I declared the variable to be… e.g.:

table with missing IML values

and

another table with missing IML values

You can see in the table what I want the numbers to be, but have thus far been unsuccessful. I have tried using %let, put, symput , and symputx without success.

call symput(t1_sum, cols[1,1]) ;

%let t2_sum = put(cols[1,2]) ;
%let t1_per = perc[1,1] ;
%let t2_per = perc[1,2] ; 



%let t1_f = tab[1,1] ;
%let t1_m = tab[2,1] ;
%let t2_f = tab[1,2] ;
%let t2_m = tab[2,2] ;

%let t1_f_p = cell_perc[1,1] ;
%let t1_m_p = cell_perc[2,1] ;
%let t2_f_p = cell_perc[1,2] ;
%let t2_m_p = cell_perc[2,2] ;

Blerg…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T21:14:29+00:00Added an answer on June 16, 2026 at 9:14 pm

    After much searching, and finding some help here on SO, I was able to piece the answer together.

    1. The output value has to be a string
    2. The name of the macro variable has to be in quotes
    3. The call has to be to symputx in order to trim extra whitespace (when compared to symput)

    Code to extract IML values to macro variables

    call symputx('t1_sum', char(cols[1,1])) ;
    call symputx('t2_sum', char(cols[1,2])) ;
    
    call symputx('t1_per', char(perc[1,1])) ;
    call symputx('t2_per', char(perc[1,2])) ;
    
    call symputx('t1_f' , char(tab[1,1])) ;
    call symputx('t1_m' , char(tab[2,1])) ;
    call symputx('t2_f' , char(tab[1,2])) ;
    call symputx('t2_m' , char(tab[2,2])) ;
    
    call symputx('t1_f_p' , char(cell_perc[1,1])) ;
    call symputx('t1_m_p' , char(cell_perc[2,1])) ;
    call symputx('t2_f_p' , char(cell_perc[1,2])) ;
    call symputx('t2_m_p' , char(cell_perc[2,2])) ;
    
    call symputx('p_val' , char(round(p_chi_1, .001))) ;
    

    Partial code used to build table using old SAS %PRNTINIT macro

    ...
    %print("Female",            column = 1,  just = center  );
    %print("&t1_f (&t1_f_p)",   column = 2,  just = center  );
    %print("&t2_f (&t2_f_p)",   column = 3,  just = center  );
    %print(,                    column = 4,  just = center  );
    %print(proc = newrow);
    
    %print("Male",              column = 1,  just = center  );
    %print("&t1_m (&t1_m_p)",   column = 2,  just = center  );
    %print("&t2_m (&t2_m_p)",   column = 3,  just = center  );
    %print("&p_val",            column = 4,  just = center  );
    ...
    

    The desired result:

    table detail with correct numbers

    additional table detail with correct numbers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just have one parameter that can take two values. I would like to
I would like to take a field and replace all characters that are not
I would like to take the words of a sentence, if that word has
What I would like to take ownership of a hid device that may already
I would like to take the Roman Numeral value stored in the object and
Take the Winlogon registry section, I would like PowerShell to display the Data value
I would like to take a string representation of a set and parse it.
I would like to take a specific part of the last line of a
I would like to take the memory generated from my struct and push it
I'm working in python 2.6 and I would like to take gpmetisfile.txt.part.4 and return

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.