BookmarkSubscribeRSS Feed
matt23
Quartz | Level 8

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?

 

8 REPLIES 8
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
matt23
Quartz | Level 8
I know but how would I make new variables for every month ?
PaigeMiller
Diamond | Level 26

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?

--
Paige Miller
matt23
Quartz | Level 8
I just need this for a basic sgplot with series. I know I can just use
group=month but my version of sas does not have the new options to play
with individual lines and stuff when it's grouped by month. So I'm trying
to do sgplot with individual series for each month.
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
matt23
Quartz | Level 8
Yea I know and I tried. But I have an older version of SAS EG so I don't
have styleattrs or mapattrs so I don't really have a choice. Thank you
though
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Astounding
PROC Star

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.

sas-innovate-2024.png

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.

 

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.

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
  • 8 replies
  • 939 views
  • 0 likes
  • 3 in conversation