BookmarkSubscribeRSS Feed
R_Win
Calcite | Level 5

data l; input id age; cards; 1 2 3 4 run; i want to create a macro do loop it and calculate it for ex data l2; input  amt rupees; cards; 3 4 5 6 run; now i wnat to usae the macro and calulate dynamically proc sql; select count(*) into :cnt from l2; %macro cal; %do i =1 %to &cnt; data l2; set l2; amt =&id*2; rupees=&age*2; run; %end; %mend; %cal; output for l2 6 8 10 12

1 REPLY 1
R_Win
Calcite | Level 5

data l; input id age; cards; 2 2 2 2 run; data l2; input  amt rupees; cards; 3 4 5 6 run; proc sql; select count(*) into :cnt from l2; quit; %macro cal; %do i =1 %to &cnt; data _null_; set l; call symput('id',id); call symput('age',age); run; data l2; set l2; amt =amt *&id; rupees=rupees*&age; run; %end; %mend; %cal; output shd be for L2 6 8 10 12

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1 reply
  • 786 views
  • 0 likes
  • 1 in conversation