BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hello everyone, I am new to SAS and I'm wondering how I could loop a procedure (if possible that is).

I have written this:

options fmtsearch= (projet.formats) ;
PROC PRINT data=PROJET.CORAIL noobs;
DO Region=1 to 6;
VAR Economic_Health Risk Population;
FORMAT Region Region.;
FORMAT Risk Risk.;
FORMAT Economic_Health Economic_Health.;
END;
RUN;

But I get an error which says "Statement is not valid or it is used out of proper order". I can obtain a right result if I remove the DO statement and put a WHERE Region=1 statement but this would rewriting the procedure 5 times, which doesn't seem very practical in my opinion. What are the possible alternative?

Thank-you in advance.
2 REPLIES 2
Flip
Fluorite | Level 6
A couple of options:


PROC PRINT data=PROJET.CORAIL noobs;
by region;
VAR Economic_Health Risk Population;
FORMAT Region Region.;
FORMAT Risk Risk.;
FORMAT Economic_Health Economic_Health.;
RUN;


or
%macro loopprt;
%do Region=1 %to 6 ;

PROC PRINT data=PROJET.CORAIL noobs;
where region = &region;
VAR Economic_Health Risk Population;
FORMAT Region Region.;
FORMAT Risk Risk.;
FORMAT Economic_Health Economic_Health.;

RUN;
%END;
%loopprt;
deleted_user
Not applicable
Thank-you, the 1st method mentioned with the BY statement works well.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 1153 views
  • 0 likes
  • 2 in conversation