BookmarkSubscribeRSS Feed
sfw_09
Calcite | Level 5

Hi,

 

I currently have a program that outputs a new data set that contains results of the proc surveyfreq procedure below: 

proc surveyfreq data=2016;
weight finalwt;
table (gender grade age race hhincome)*(eversmk cursmk)/ cl row nocellpct nostd nofreq nowt nototal; ods output CrossTabs=table1;

data table1;
retain gender grade age race hhincome eversmk cursmk RowPercent RowLowerCL RowUpperCL; set table1(drop=F_cursmk LowerCL UpperCL Table _SkipLine); run;

I would like to develop a macro that calls in different years of data instead of repeating the same surveyfreq procedure on each year of data I have. The above program is for 2016 data, but I would like a macro that calls in 2015, 2014, etc and outputs the same resulting statistics. I have little experience with developing macro code, so any advice would be appreciated. Thank you!

3 REPLIES 3
cau83
Pyrite | Level 9

You can create a macro variable like this:

%let year=2016;

If you have all the years in one data set, you can combine this with a where statement like so:

proc surveyfreq data-yourdata;
    where year=&year;
    other code;
run;

Unless there's a reason you need it to be separate you may be better off by using a BY statement instead though. Then you would just run the proc once, and get all of your output in one place.

proc surveyfreq data=yourdata;
    BY year;
    other code;
run;
ballardw
Super User

1) combine the data sets

2) make sure you have two variables with the year value for each of the data sets

3) One of those variables goes on a STRATA statement

4) the Other Year variable goes in your tables statement to get a summary by year. (can't have a variable on the strata statement as a tables variables)

 

No macro needed

 

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1217 views
  • 0 likes
  • 4 in conversation