Dear all,
I created multiple macro vairable stores differnt number of patients cnt using proc sql statements.
I would like to put these macro vairables together using the following data step, however, there is error message. I am wondering whether you can help me with how to put those variable together . Thank you very much !
data cnt;
input cnt1 mark $ 30;
cards;
&peme peme
&beva beva
&peme_beva peme_beva
&IOIO IOIO
&IOBF IOBF
&IOAF IOAF
&cntline2 cntline2
&cntline2_chemo cntline2_chemo
&cntline2_cohort cntline2_cohort
&cntline2_chemo_cohort cntline2_chemo_cohort
&Refra Refra
&refra_12_y refra_12_y
&refra_12_n refra_12_n
&refra_9_y refra_9_y
&refra_9_n refra_9_n
&refra_12_y_b refra_12_y_b
&refra_12_n_b refra_12_n_b
&refra_9_y_b refra_9_y_b
&refra_9_n_b refra_9_n_b
;
run;
That is bad coding, Try symget() to retrieve these macro variables. %let peme=x; %let beva=y; data cnt; input mark $; cnt1=symget(mark); cards; peme beva ; run;
That is bad coding, Try symget() to retrieve these macro variables. %let peme=x; %let beva=y; data cnt; input mark $; cnt1=symget(mark); cards; peme beva ; run;
As noted, you'd be better off storing the values as you calculated them, rather than after the fact.
Within a cards; block, macro triggers won't work.
Use the symget function to retrieve macro values instead, as @Ksharp already suggested.
Could we take a step back here. What is it your actually trying to do - test data/required output. Why for instance are you counting numbers of X, and then putting that into a macro variable, then reading that data into a dataset? It seems to be a very log way around doing a simple insert:
proc sql; insert into RESULTS set TEST="ABC", RESULT=(select count(distinct SUBJECT) from ABC); quit;
However, even that seems a bit convoluted. Why not just use the summary procedures and such like? If its different datasets, and you need a count by dataset then here is simple example of how to combine the datasets (in your case you would just need to keep subject variable) then use the name of the dataset to create one dataset output with counts per dataset:
data tmp1 tmp2; set sashelp.class; if sex="M" then output tmp1; else output tmp2; run; data have; length name $20; set tmp: indsname=n; name=n; run; proc sql; create table WANT as select NAME, AGE, count(*) as RESULT from HAVE group by NAME,AGE; quit;
As with anything there is never a need to resort to macro code.
Dear all,
Thank you very much for your valueable knowledge !
That really helps !
Ivy
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.