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.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1861 views
  • 0 likes
  • 2 in conversation