DATA Step, Macro, Functions and more

Whats wrong with this code

Reply
Occasional Contributor
Posts: 10

Whats wrong with this code


proc sort data = waves;
by ssuid eentaid epppnum srefmon;
run;

data
wave5sipp
(rename = (tage=tage1
tptotinc=ptotinc1
srefmon=srefmon1 ))
wave6sipp
(rename =(tage=tage2
tptotinc=ptotinc2
srefmon=srefmon2 ));
set waves;
select (srefmon);
when (1) output wave5sipp;
when (2) output wave6sipp;
end;
run;

 

log message:

 

ERROR: Unsatisfied WHEN clause and no OTHERWISE clause at line 2120 column 5.
SSUID=019128000932 SWAVE=5 SREFMON=3 RHCALMN=5 SHHADID=11 TFIPSST=22
THOTHINC=0 RFID=3 RFNKIDS=0 RFOKLT18=0 EENTAID=11 EPPPNUM=101 ESEX=2 ERACE=1
EORIGIN=2 TAGE=47 ERRP=6 EMS=4 ETYPMOM=-1 ETYPDAD=-1 TPEARN=2800
TPTOTINC=2800 RENROLL=3 EEDUCATE=37 EJBHRS1=40 _ERROR_=1 _N_=5
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 5 observations read from the data set WORK.WAVES.
WARNING: The data set WORK.WAVE5SIPP may be incomplete. When this step was
stopped there were 2 observations and 25 variables.
WARNING: Data set WORK.WAVE5SIPP was not replaced because this step was
stopped.
WARNING: The data set WORK.WAVE6SIPP may be incomplete. When this step was
stopped there were 2 observations and 25 variables.
WARNING: Data set WORK.WAVE6SIPP was not replaced because this step was
stopped.

PROC Star
Posts: 7,363

Re: Whats wrong with this code

add an otherwise; clause to your select statement.

 

Ref: Null statements that are used in OTHERWISE statements prevent SAS from issuing an error message when all WHEN conditions are false.

 

Art, CEO, AnalystFinder.com

 

Respected Advisor
Posts: 4,649

Re: Whats wrong with this code

select (srefmon);
when (1) output wave5sipp;
when (2) output wave6sipp;
otherwise;
end;
PG
Super User
Posts: 17,829

Re: Whats wrong with this code

What do you want your code to do when SREFMON=3 in the 5th record? Currently this is causing your error, because it's not included in your SELECT statement, but you should deal with it explicitly IMO. If you had used IF/THEN it would not have errored but would have set the value to missing. It's good to note the difference between these methods of recoding data.

 

 

PS. In real life, make sure that you can post your errors because they may contain confidential information. Since this is homework I assume there's no issue with your data here. 

 

ERROR: Unsatisfied WHEN clause and no OTHERWISE clause at line 2120 column 5.
SSUID=019128000932 SWAVE=5 SREFMON=3 RHCALMN=5 SHHADID=11 TFIPSST=22
THOTHINC=0 RFID=3 RFNKIDS=0 RFOKLT18=0 EENTAID=11 EPPPNUM=101 ESEX=2 ERACE=1
EORIGIN=2 TAGE=47 ERRP=6 EMS=4 ETYPMOM=-1 ETYPDAD=-1 TPEARN=2800
TPTOTINC=2800 RENROLL=3 EEDUCATE=37 EJBHRS1=40 _ERROR_=1 _N_=5

 

 

 

 


Mike7 wrote:


proc sort data = waves;
by ssuid eentaid epppnum srefmon;
run;

data
wave5sipp
(rename = (tage=tage1
tptotinc=ptotinc1
srefmon=srefmon1 ))
wave6sipp
(rename =(tage=tage2
tptotinc=ptotinc2
srefmon=srefmon2 ));
set waves;
select (srefmon);
when (1) output wave5sipp;
when (2) output wave6sipp;
end;
run;

 

log message:

 

ERROR: Unsatisfied WHEN clause and no OTHERWISE clause at line 2120 column 5.
SSUID=019128000932 SWAVE=5 SREFMON=3 RHCALMN=5 SHHADID=11 TFIPSST=22
THOTHINC=0 RFID=3 RFNKIDS=0 RFOKLT18=0 EENTAID=11 EPPPNUM=101 ESEX=2 ERACE=1
EORIGIN=2 TAGE=47 ERRP=6 EMS=4 ETYPMOM=-1 ETYPDAD=-1 TPEARN=2800
TPTOTINC=2800 RENROLL=3 EEDUCATE=37 EJBHRS1=40 _ERROR_=1 _N_=5
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 5 observations read from the data set WORK.WAVES.
WARNING: The data set WORK.WAVE5SIPP may be incomplete. When this step was
stopped there were 2 observations and 25 variables.
WARNING: Data set WORK.WAVE5SIPP was not replaced because this step was
stopped.
WARNING: The data set WORK.WAVE6SIPP may be incomplete. When this step was
stopped there were 2 observations and 25 variables.
WARNING: Data set WORK.WAVE6SIPP was not replaced because this step was
stopped.


 

Ask a Question
Discussion stats
  • 3 replies
  • 313 views
  • 2 likes
  • 4 in conversation