Desktop productivity for business analysts and programmers

Can I loop this process?

Reply
Frequent Contributor
Posts: 89

Can I loop this process?

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?

 

Respected Advisor
Posts: 3,277

Re: Can I loop this process?

[ Edited ]

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
Frequent Contributor
Posts: 89

Re: Can I loop this process?

Posted in reply to PaigeMiller
I know but how would I make new variables for every month ?
Respected Advisor
Posts: 3,277

Re: Can I loop this process?

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
Frequent Contributor
Posts: 89

Re: Can I loop this process?

Posted in reply to PaigeMiller
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.
Respected Advisor
Posts: 3,277

Re: Can I loop this process?

[ Edited ]

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
Frequent Contributor
Posts: 89

Re: Can I loop this process?

Posted in reply to PaigeMiller
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
Respected Advisor
Posts: 3,277

Re: Can I loop this process?

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
Super User
Posts: 6,934

Re: Can I loop this process?

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.

Ask a Question
Discussion stats
  • 8 replies
  • 87 views
  • 0 likes
  • 3 in conversation