BookmarkSubscribeRSS Feed
Pratima67301
Calcite | Level 5

data new dataset;
set Weight ;
else if Weight < 1500 then BirthWeight = "2.2 Very low <1500";
else if Weight < 2500 then BirthWeight = "2.1 Low birth <2500";
else if Weight >= 2500 and BWGT <= 4000 then BirthWeight = "2.3 2500-4000";

 

This is my code, but I have a small problem with the output.

I want to find values 2.2 <1,500 and 2.1 <2,500. However, it only provides outputs for values <1,500 and for values that are (<2,500 and >1,500). SAS does not give me results when the values overlap. Any help would be greatly appreciated.

 
 
4o
2 REPLIES 2
Astounding
PROC Star

It's difficult to comment, when your program has no chance of doing anything at all.  Here's a suggestion that may help.  On each observation, there can be only one value for BirthWeight.  So decide what you want the final data set to look like before you start programming.

mkeintz
PROC Star

Among other issues, since the code you show has an ELSE IF that is not preceded by an IF, it can not run.

 

In turn that mean the new dataset you intend to output will not be created, or will not be overwritten if it already exists.   So if the output dataset already exists and already exhibited the problems you describe, they will still be there in that unmodified dataset.

 

Show us the log of code that actually outputs data, and then we can help diagnose the problem, if it persists.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 574 views
  • 0 likes
  • 3 in conversation