BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ivy
Quartz | Level 8 Ivy
Quartz | Level 8

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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;

View solution in original post

5 REPLIES 5
Ksharp
Super User
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;

Reeza
Super User

As noted, you'd be better off storing the values as you calculated them, rather than after the fact. 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

 

Ivy
Quartz | Level 8 Ivy
Quartz | Level 8

Dear all,

 

Thank you very much for your valueable knowledge !

 

That really helps !

 

Ivy 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 976 views
  • 0 likes
  • 5 in conversation