Help using Base SAS procedures

Looping a PROC PRINT

Reply
N/A
Posts: 0

Looping a PROC PRINT

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.
Super Contributor
Posts: 359

Re: Looping a PROC PRINT

Posted in reply to deleted_user
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;
N/A
Posts: 0

Re: Looping a PROC PRINT

Thank-you, the 1st method mentioned with the BY statement works well.
Ask a Question
Discussion stats
  • 2 replies
  • 105 views
  • 0 likes
  • 2 in conversation