BookmarkSubscribeRSS Feed
sgallen
Calcite | Level 5

Hi, I am extremely new to SAS and am struggling to resolve this error message. I am trying to run summary stats using proc means on a data set and categorizing the columns by country and year (this part works on its own). Now I am trying to recode the variables I selected and continue to get an error code. I have attached my code and the error statements below.

 

proc means data="/folders/myfolders/PMA/pma.sas7bdat";
class COUNTRY YEAR;
var HASWATER;
var HASWTROUT2HR HASELECTRC HASELECOUT2HR HANDWASHNUM RUNWTRPRES SOAPPRES SHARPDISP 
;
WATER= .;
IF (HASWATER=0) THEN (WATER=0);
IF (HASWATER=1) THEN (WATER=1);
IF (HASWATER=98) THEN (WATER=.);
Title 'Summary Stats by Country';

run;
 73         proc means data="/folders/myfolders/PMA/pma.sas7bdat";
 NOTE: Data file _TEMP1.PMA.DATA is in a format that is native to another host, or the file encoding does not match the session 
       encoding. Cross Environment Data Access will be used, which might require additional CPU resources and might reduce 
       performance.
 74         class COUNTRY YEAR;
 75         var HASWATER;
 76         var HASWTROUT2HR HASELECTRC HASELECOUT2HR HANDWASHNUM RUNWTRPRES SOAPPRES SHARPDISP
 77         ;
 78         WATER= .;
            _____
            180
 79         IF (HASWATER=0) THEN (WATER=0);
            __
            180
 80         IF (HASWATER=1) THEN (WATER=1);
            __
            180
 81         IF (HASWATER=98) THEN (WATER=.);
            __
            180
 ERROR 180-322: Statement is not valid or it is used out of proper order.
 82         Title 'Summary Stats by Country';
 83         
 84         run;
3 REPLIES 3
PaigeMiller
Diamond | Level 26
WATER= .;
IF (HASWATER=0) THEN (WATER=0);
IF (HASWATER=1) THEN (WATER=1);
IF (HASWATER=98) THEN (WATER=.);

 

These are DATA step commands. You cannot use them in PROC MEANS. You probably want a DATA step with these command BEFORE running PROC MEANS.

--
Paige Miller
sgallen
Calcite | Level 5

Okay thank you so much! 

How does the data step work? I know that I have to have data and then set below that. What to do I put after each of these?

PaigeMiller
Diamond | Level 26

Example

 

data new;
    set yourdatasetname;
    WATER= .;
    IF HASWATER=0 THEN WATER=0;
    else IF HASWATER=1 THEN WATER=1;
    else IF HASWATER=98 THEN WATER=.;
run;
--
Paige Miller

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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