I have never done any loops so I don't know if this process can be done but Can I code this so I don't have to do it for all 12 Months?
Here's what I'm doing:
proc means data=have; where Month in (1); by Month hour; var Lo Te De Wi CC Sr Rf; output out=MeanJan mean=; run; proc means data=have; where Month in (2); by Month hour; var Lo Te De Wi CC Sr Rf; output out=MeanFeb mean=; run; data avrg; merge MeanJan(rename=(Lo=LeJan Te=TeJan De=DeJan Wi=WiJan CC=CCJan SR=SRJan RF=RFJan)) MeanFeb(rename=(Lo=LoFeb Te=TeFeb De=DeFeb Wi=WiFeb CCr=CCFeb Sr=SRFeb Rfl=RFFeb)) ; by Hour; keep LeJan TeJan.........; run;
If I can loop this, how?
If you run the PROC MEANS with out the WHERE statement, you get one output data set containing the means of each month. There's no need to run 12 different PROC MEANS here.
When you try to create data set AVRG, this is where you start doing things that probably ought to be avoided. Turning a long data set into a wide data set usually is not a good idea, it doesn't help you in the future analyses you want to do (although I suppose there are always exceptions). So, without strong justification, there is no need to loop this either.
Why do you want new variables for each month? What analysis are you going to do with all of these variables once you have them?
If you mean options like GROUPLP, GROUPLC and GROUPMC in PROC SGPLOT, yes, they are not in older versions of SGPLOT. However the STYLEATTRS statement is still available in PROC SGPLOT to control line colors and line patterns and markers.
So, don't do the huge amount of work to make separate columns. Use PROC SGPLOT with GROUP= and STYLEATTRS. It's a huge amount simpler, and less error prone.
If your version is really that old — PLEASE STATE THE VERSION NUMBER OF SAS THAT YOU HAVE by opening Enterprise Guide and the run the following statement: proc setinit; run; — you can then use PROC GPLOT and you still don't need to create all of these columns.
Even with your restrictions, you would do better to keep the data in one data set. Just apply the WHERE statement later, in the plotting procedure. Even if using a BY statement isn't feasible, looping isn't all that difficult. Get a version that works for one month, and we can expand it to all 12 months, using just one summary data set.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.