i am having a data set data main; input sal; cards; 100 200 run; data mon_sal; input days; cards; 2 3 run; %macro sas_cal; proc sql; select count(*) into :cou from mon_sal; select sal into s1-s&cou from main; quit; data mon_sal; set mon_sal; do i=1 %to &cou; mo_days=days*s&cou; %end; run; %mend; %sa_cal; I am trying to iterate it as the same calulation i want to do for few datasets i want the sal from one dataset and days from another datasets to create new variable how can i macro tise it output of mon_sal; days mo_days 2 200 3 600
Ref this
This does not look like a problem where you would need to get into the complexity of MACRO programming. Normal programming will do just fine.
It will probably work better if your two source datasets had some type of ID variable to identify the rows so that you can match the SAL to the proper DAYS. Perhaps MONTH?
If you are willing to assume that the tables should match row by row then you can use merge without a BY statement or two independent SET statements to read one row from each source table per loop of the data step.
data main;
input sal;
cards;
100
200
run;
data mon_sal;
input days;
cards;
2
3
run;
data mon_sal;
set main;
set mon_sal;
mo_days = days*sal;
run;
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.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.