BookmarkSubscribeRSS Feed
jacob_warren
Calcite | Level 5

Below my code and attached is an excel document that contains the original SAS data set I am working with and the prints from my code.  In my code I have created a macro that will create and print a new data set based on a starting year, ending year, and a month.  The problem is that I want to be able to create multiple data sets at once by calling on more than one month at a time.  So in my code were I am using:

%getSnowMonths()

%getSnowMonths(Month = Jan)

%getSnowMonths(Month = Feb)

to create a data set for Dec (default) Jan, and February by calling on my macro 3 times, I want to be able to use

%getSnowMonths(Month = Dec Jan Feb)

to create the same data sets and prints.

This is actually a problem from a homework assignment I am working on (and having some trouble with) for a Master's class.  Any suggestions or help would be appreciated.  Thanks!

%macro getSnowMonths(data = "/courses/u_rit.edu1/i_581369/c_1057/wk3/rochestersnowfalltab.txt", yearStart=1905, yearEnd=1930, Month = Dec, prefix=Snow);

data snow;

      Infile &data Firstobs = 5  OBS = 122 DLM = '09'x;

            Input Season 4. Sep Oct Nov Dec Jan Feb Mar Apr May Total;

            If Sep = . then Sep = 0;

            If Oct = . then Oct = 0;

            If Nov = . then Nov = 0;

            If Apr = . then Apr = 0;

            If May = . then May = 0;

      Options errors = 1000;

Run;

data &prefix&month&yearStart&yearEnd;

set snow;

keep Season &Month;

where Season >=&yearStart and Season <=&yearEnd;

run;

Proc print data = &prefix&month&yearStart&yearEnd NoObs label;

label &Month = 'Snow';

Title "Rochester Snowfall in &Month";

Footnote "Created on &sysday %sysfunc(today(), mmddyy10.) at &systime.";

run;

%mend getSnowMonths;

%getSnowMonths()

%getSnowMonths(Month = Jan)

%getSnowMonths(Month = Feb)

options symbolgen mprint;


output.jpg
4 REPLIES 4
art297
Opal | Level 21

On principle I can't give you a direct answer to a homework question, but I can possibly lead you in the right direction.  Take a look at: http://www2.sas.com/proceedings/sugi29/128-29.pdf

It (and other articles you can find searching for %scan macro sas example list "%do %while" ) can provide the info you probably need.

One easy solution, if you don't want or need to re-write the code, is to simply write a macro that loops through a parameter of months and, for each, runs your current macro.

HTH,

Art

jacob_warren
Calcite | Level 5

Thanks Art!  I will definitely give that a read and see where it gets me.  I'll let you know if I make progress on it.

jacob_warren
Calcite | Level 5

Art just wanted to say thanks again.  I ended up having to find another document to read as well but I did end up getting it figured out.

art297
Opal | Level 21

Jacob,

If you want feedback on the code you wrote, just post it and I, or a number of us, will likely give you some pointers.  While it was refreshing to hear a student admit they were doing a project, that makes it difficult for any of us who have taught to respond.  However, I think you will find sites like this, and SAS-L, a nice place to further one's learning opportunities.

Regardless, glad to hear that you were able to solve your problem.

Art

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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1547 views
  • 3 likes
  • 2 in conversation