BookmarkSubscribeRSS Feed
R_Win
Calcite | Level 5

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

2 REPLIES 2
R_Win
Calcite | Level 5

Ref this

Tom
Super User Tom
Super User

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;

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!

What is Bayesian Analysis?

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.

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
  • 2 replies
  • 835 views
  • 0 likes
  • 2 in conversation