BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

 

I am able to call the macro variables values created by datastep(withoutmacro) where ever I can by calling "&b1,&c1,&d1,&e1".

 

But the macro variables created by macro step(shown below), I am not able call the macro variables. When I use "&b1,&c1,&d1,&e1" in a datastep,the values of the macrovariables are not called

 

Please help how can I use the macro variables created by the  macro step below. Thank you very much

 

data one;
input NS trt01a $ ;
datalines;
45 150MG
71 300MG
15 75MG
131 TOTAL
;
%macro two(var1=,var2=,var3=,var4=,var5=,var6=,var7=);
data &var2;
set &var1;
if trt01a='75MG' then trt="&var3";
if trt01a='150MG' then trt="&var4";
if trt01a='300MG' then trt="&var5";
if trt01a='TOTAL' then trt="&var6";
run;


data &var7;
set &var2;
call symputx(trt,ns);
run;
%mend;
%two(var1=one,var2=two,var3=b1,var4=c1,var5=d1,var6=f1,var7=three);
data one;
input NS trt01a $ ;
datalines;
45 150MG
71 300MG
15 75MG
131 TOTAL
;
data withoutmacro;
set one;
if trt01a='75MG' then trt="b1";
if trt01a='150MG' then trt="c1";
if trt01a='300MG' then trt="d1";
if trt01a='TOTAL' then trt="e1";
run;
data withoutmacro1;
set withoutmacro;
call symputx(trt,ns);
run;  

 

 

5 REPLIES 5
art297
Opal | Level 21

You didn't show any code where you were attempting to apply macro variables outside of the macro, thus we can only guess.

 

Possibly, you simply have to define the macro variables you want to use outside of the macro as GLOBAL. Otherwise, they will simply be local to the macro.

 

Art, CEO, AnalystFinder.com

 

knveraraju91
Barite | Level 11

Thank you very much. % global statemnt worked.  Thank you

Reeza
Super User

I think you need to start over. I would bet money on the method you're using here is inefficient and clunky. It looks like you're trying to transpose/recode using macros when other options are probably better. 

 

Can you start from scratch by posting what you have and what you need? Make it small/simple enough to use on the forum, but complex enough to capture all your requirements.

knveraraju91
Barite | Level 11

Thank you very much for the reply. Some one suggested me to use "%global b1 c1 d1 f1;" in the macro. I think I got my answer. Thank you very much for the outstanding support

Tom
Super User Tom
Super User

Works fine for me.

2317  data one;
2318  input NS trt01a $ ;
2319  datalines;

NOTE: The data set WORK.ONE has 4 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


2324  ;
2325  data withoutmacro;
2326    set one;
2327    if trt01a='75MG' then trt="b1";
2328    if trt01a='150MG' then trt="c1";
2329    if trt01a='300MG' then trt="d1";
2330    if trt01a='TOTAL' then trt="e1";
2331    call symputx(trt,ns);
2332  run;

NOTE: There were 4 observations read from the data set WORK.ONE.
NOTE: The data set WORK.WITHOUTMACRO has 4 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


2333
2334  %put &=b1 &=c1 &=d1 &=e1;
B1=15 C1=45 D1=71 E1=131

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 802 views
  • 1 like
  • 4 in conversation