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

Hi,

 

I am executing a macro inside a data step and passing the data step variable to the macro.

 

But only last record variable is passed all the time (like my loop executed 2 times and 2 times last record variable only passed as a parameter).

 

The output should be 

APPDIRECT_PROD_2018011001.dat|20180110|20180110|0000000001|APPDIRECT_PROD_2018011002.|ctl

APPDIRECT_PROD_2018011002.dat|20180110|20180110|0000000002|APPDIRECT_PROD_2018011002.|ctl

 

But I am getting

 

APPDIRECT_PROD_2018011002.dat|20180110|20180110|0000000002|APPDIRECT_PROD_2018011002.|ctl

APPDIRECT_PROD_2018011002.dat|20180110|20180110|0000000002|APPDIRECT_PROD_2018011002.|ctl

 

Where exactly the issue?

 

Thanks,

Swathi

1 ACCEPTED SOLUTION
5 REPLIES 5
Kurt_Bremser
Super User

You are repeatedly creating macro variable new with call symput.

You are pushing macro calls onto the execution stack that contain the macro variable name, not it's value.

Since the macros won't execute before the data step has finished, all macro calls will use the last value put into macro variable new.

 

Instead of setting macro variables, use data step values in the call execute.

sfffdg
Obsidian | Level 7

Thank you Sir,for your reply.

 

I changed the code to  the variable directly,instead of the macro variable as i don't want to hardcode the valueas below.

x = cats( '%nrstr(%b(id))' ) ;

 

then the output is as below.

1 + %b(id)
id
2 + %b(id)
id

 

instead of the resolved variable value.

 

Is there any approach to achieve this?

 

Thanks!!

 

 

sfffdg
Obsidian | Level 7

Thank you sir!!

Tom
Super User Tom
Super User

So let's eliminate the complexity of your data step from this problem and concentrate on just the CALL EXECUTE issue.

So first create your dataset and then use a DATA _NULL_ step to generate the macro calls.

%macro a ;
data FILELIST ;
  ....
  output;
  ....
run;

data _null_;
  set FILELIST;
  call execute(cats('%nrstr(%b)(',id,')'));
run;
%mend a;

Now you can also probably make your data step much simpler (why are you calling CATT() function on string literals?), but perhaps you can leave that for another question.

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
  • 7364 views
  • 0 likes
  • 3 in conversation