BookmarkSubscribeRSS Feed
Lea1702
Fluorite | Level 6

Good day to everybody,

I need some help to re-write my data code.

I'm trying to compare children's weight and height with a WHO pattern, so I made the following code, but the problem is that results are not being categorizing according to my code, and I'm just getting just numbers 2 and sometimes jus full three. I'm attaching my code. I will really appreciate your help.

 

/*weight vs age*/

if ch_sex=1 and ch_age_months=12 and chweightd<=6.9 then pvse=1 ; else
if ch_sex=1 and ch_age_months=12 and (chweightd>6.9 or chweightd<=7.7) then pvse=2 ;
if ch_sex=1 and ch_age_months=12 and (chweightd>7.7 or chweightd<=10.8) then pvse=3 ; else
if ch_sex=1 and ch_age_months=12 and chweightd>10.8 then pvse=4 ;

 

if ch_sex=2 and ch_age_months=12 and chweightd<=6.3 then pvse=1 ; else
if ch_sex=2 and ch_age_months=12 and (chweightd>6.3 or chweightd<=7.0) then pvse=2 ;
if ch_sex=2 and ch_age_months=12 and (chweightd>7.0 or chweightd<=10.1) then pvse=3 ; else
if ch_sex=2 and ch_age_months=12 and chweightd>10.1 then pvse=4 ;

/*PVSE>> 1=severe low weight   2=low weight   3=normal   4=possible growth problem*/

 

/*weight vs height*/
if ch_sex=2 and chheightd=45 and chweightd<=1.9 then pvst=1 ;
if ch_sex=2 and chheightd=45 and (chweightd>1.9 or chweightd<=2.1) then pvst=2 ;
if ch_sex=2 and chheightd=45 and (chweightd>2.1 or chweightd<=2.7) then pvst=3 ;
if ch_sex=2 and chheightd=45 and (chweightd>2.7 or chweightd<=3.0) then pvst=4 ;
if ch_sex=2 and chheightd=45 and (chweightd>3.0 or chweightd<=3.3) then pvst=5 ;
if ch_sex=2 and chheightd=45 and chweightd>3.3 then pvst=6 ;

if ch_sex=1 and chheightd=45 and chweightd<=1.9 then pvst=1 ;
if ch_sex=1 and chheightd=45 and (chweightd>1.9 or chweightd<=2.0) then pvst=2 ;
if ch_sex=1 and chheightd=45 and (chweightd>2.0 or chweightd<=2.7) then pvst=3 ;
if ch_sex=1 and chheightd=45 and (chweightd>2.7 or chweightd<=3.0) then pvst=4 ;
if ch_sex=1 and chheightd=45 and (chweightd>3.0 or chweightd<=3.3) then pvst=5 ;
if ch_sex=1 and chheightd=45 and chweightd>3.3 then pvst=6 ;
/*PVST >> 1= severe malnourished   2=malnourished   3=normal   4=risk of overweight   5=overweight   6=obesity*/

 

/*height vs age*/

if ch_sex=2 and ch_age_months=0 and chheightd<=43.6 then tvse=1 ;
if ch_sex=2 and ch_age_months=0 and (chheightd>43.6 or chheightd<=45.4) then tvse=2 ;
if ch_sex=2 and ch_age_months=0 and (chheightd>45.4 or chheightd<=54.7) then pvse=3 ;
if ch_sex=2 and ch_age_months=0 and chheightd>54.7 then pvse=4 ;

if ch_sex=1 and ch_age_months=0 and chheightd<=44.2 then tvse=1 ;
if ch_sex=1 and ch_age_months=0 and (chheightd>44.2 or chheightd<=46.1) then tvse=2 ;
if ch_sex=1 and ch_age_months=0 and (chheightd>46.1 or chheightd<=55.6) then pvse=3 ;
if ch_sex=1 and ch_age_months=0 and chheightd>55.6 then pvse=4 ;
/*TVSE >> 1= severe low height  2=low height   3=normal  4=tall */

9 REPLIES 9
PeterClemmensen
Tourmaline | Level 20

You can simplify your code by using a SELECT statement in your data step. A simple google search will do the trick

 

Also check out the article 

 

https://blogs.sas.com/content/iml/2016/06/20/select-when-sas-data-step.html

Reeza
Super User

chweightd>1.9 or chweightd<=2.1

 

This OR condition will almost always evaluate to true. 

Astounding
PROC Star

Your problems are caused by inconsistent use of the word ELSE, as well as using OR when you should use AND.  For example, note that this condition must be true every time:   (chweightd>6.9 or chweightd<=7.7) 

 

Here is a style that will run faster and illustrates better logic:

 

if ch_sex=1 and ch_age_months=12 then do;

   if chweightd <= 6.9 then pvse=1 ; else
   if chweightd<=7.7 then pvse=2 ; else
   if chweightd<=10.8 then pvse=3 ; else
   pvse=4 ;

end;

else if ch_sex=2 and ch_age_months=12 then do;

   if chweightd<=6.3 then pvse=1 ; else
   if chweightd<=7.0 then pvse=2 ; ELSE
   if chweightd<=10.1 then pvse=3 ; else
   pvse=4 ;

end;

 

You'll need to fill in the rest.

Lea1702
Fluorite | Level 6

Dear #Astounging thanks for your help.

Althought I changed my code according to your suggestion the results are same. I tryed to re-write my previous code but this time erasing "else" and i could get some results but still some values are wrong. Some should have twos but it appears threes.

Astounding
PROC Star

We'll need to see what your code looks like now ... too many possibilities to guess at.

Lea1702
Fluorite | Level 6

Dear #Astounding, thanks one more time for replying. What happens when i changed the weight vs age proc using 'then do' statement was that all results changed into twos. So, i decided to changed the code to the initial version but erasing all 'else' words, and I get reuslts. Then, I thought your suggestion could work in my "weight vs height" code but results were same..I mean twos. Then I tryied to use a different sintax as you can see, although there were values shouldn't be condidered for the analysis in the results appeared numbers five and six. I'm new in sas and I dont know how i can improve my code.



/*weight vs age*/ if chweightd=. then delete ; if chheightd=. then delete ; if ch_sex=2 and ch_age_months=12 and chweightd<=6.3 then pvse=1 ; if ch_sex=2 and ch_age_months=12 and (chweightd>6.3 or chweightd<=7.0) then pvse=2 ; if ch_sex=2 and ch_age_months=12 and (chweightd>7.0 or chweightd<=10.1) then pvse=3 ; if ch_sex=2 and ch_age_months=12 and chweightd>10.1 then pvse=4 ; if ch_sex=2 and ch_age_months=13 and chweightd<=6.4 then pvse=1 ; if ch_sex=2 and ch_age_months=13 and (chweightd>6.4 or chweightd<=7.2) then pvse=2 ; if ch_sex=2 and ch_age_months=13 and (chweightd>7.2 or chweightd<=10.4) then pvse=3 ; if ch_sex=2 and ch_age_months=13 and chweightd>10.4 then pvse=4 ; if ch_sex=1 and ch_age_months=12 and chweightd<=6.9 then pvse=1 ; if ch_sex=1 and ch_age_months=12 and (chweightd>6.9 or chweightd<=7.7) then pvse=2 ; if ch_sex=1 and ch_age_months=12 and (chweightd>7.7 or chweightd<=10.8) then pvse=3 ; if ch_sex=1 and ch_age_months=12 and chweightd>10.8 then pvse=4 ; if ch_sex=1 and ch_age_months=13 and chweightd<=7.1 then pvse=1 ; if ch_sex=1 and ch_age_months=13 and (chweightd>7.1 or chweightd<=7.9) then pvse=2 ; if ch_sex=1 and ch_age_months=13 and (chweightd>7.9 or chweightd<=11.0) then pvse=3 ; if ch_sex=1 and ch_age_months=13 and chweightd>11.0 then pvse=4 ;
/*1=severe underweight   2=underweight   3=normal   4=possible growth problem*/
/*value series is divided by sex and completed until 60 months*/

/*weight vs height/lenght*/
if (ch_sex=2 and (chheightd>69.5 or chheightd<=70) and chweightd<=6.3) then pvst=1 ; if (ch_sex=2 and (chheightd>69.5 or chheightd<=70) and (chweightd>6.3 or chweightd<=6.9)) then pvst=2 ; if (ch_sex=2 and (chheightd>69.5 or chheightd<=70) and (chweightd>6.9 or chweightd<=9.0)) then pvst=3 ; if (ch_sex=2 and (chheightd>69.5 or chheightd<=70) and (chweightd>9.0 or chweightd<=9.9)) then pvst=4 ; if (ch_sex=2 and (chheightd>69.5 or chheightd<=70) and (chweightd>9.9 or chweightd<=10.9)) then pvst=5 ; if (ch_sex=2 and (chheightd>69.5 or chheightd<=70) and chweightd>10.9) then pvst=6 ; if (ch_sex=2 and (chheightd>70 or chheightd<=70.5) and chweightd<=6.4) then pvst=1 ; if (ch_sex=2 and (chheightd>70 or chheightd<=70.5) and (chweightd>6.4 or chweightd<=6.9)) then pvst=2 ; if (ch_sex=2 and (chheightd>70 or chheightd<=70.5) and (chweightd>6.9 or chweightd<=9.1)) then pvst=3 ; if (ch_sex=2 and (chheightd>70 or chheightd<=70.5) and (chweightd>9.1 or chweightd<=10.0)) then pvst=4 ; if (ch_sex=2 and (chheightd>70 or chheightd<=70.5) and (chweightd>10.0 or chweightd<=11.0)) then pvst=5 ; if (ch_sex=2 and (chheightd>70 or chheightd<=70.5) and chweightd>11.0) then pvst=6 ;
if (ch_sex=2 and (chheightd>70.5 or chheightd<=71) and chweightd<=6.5) then pvst=1 ;
if (ch_sex=2 and (chheightd>70.5 or chheightd<=71) and (chweightd>6.5 or chweightd<=7.0)) then pvst=2 ;
if (ch_sex=2 and (chheightd>70.5 or chheightd<=71) and (chweightd>7.0 or chweightd<=9.2)) then pvst=3 ;
if (ch_sex=2 and (chheightd>70.5 or chheightd<=71) and (chweightd>9.2 or chweightd<=10.1)) then pvst=4 ;
if (ch_sex=2 and (chheightd>70.5 or chheightd<=71) and (chweightd>10.1 or chweightd<=11.1)) then pvst=5 ;  
if (ch_sex=2 and (chheightd>70.5 or chheightd<=71) and chweightd>11.1) then pvst=6 ;
/*1= severe wasted   2=wasted   3=normal   4=risk of overweight   5=overweight   6=obesity*/

/*height vs age*/

if ch_sex=2 and ch_age_months=12 and chheightd<=43.6 then tvse=1 ;
if ch_sex=2 and ch_age_months=12 and (chheightd>43.6 or chheightd<=45.4) then tvse=2 ;
if ch_sex=2 and ch_age_months=12 and (chheightd>45.4 or chheightd<=54.7) then pvse=3 ;
if ch_sex=2 and ch_age_months=12 and chheightd>54.7 then pvse=4 ;

if ch_sex=1 and ch_age_months=12 and chheightd<=44.2 then tvse=1 ;
if ch_sex=1 and ch_age_months=12 and (chheightd>44.2 or chheightd<=46.1) then tvse=2 ;
if ch_sex=1 and ch_age_months=12 and (chheightd>46.1 or chheightd<=55.6) then pvse=3 ;
if ch_sex=1 and ch_age_months=12 and chheightd>55.6 then pvse=4 ;
/*1= severely stunted  2=stunted   3=normal  4=tall */

 

Astounding
PROC Star

Sorry, don't think I can help here.  This version of the code doesn't reflect any of the suggestions that I made previously.  Best of luck.

Tom
Super User Tom
Super User

Also what do you want to do with missing values for the weight?  With your current code

ch_sex=1
ch_age_months=12
chweightd=.

will get codes as pvse=1 since missing values are less than any real number.

Lea1702
Fluorite | Level 6

I am analyzing children's weight and height comparing them with WHO's pattern, to know their nutritional status.

So, I do really need that information. I'm deleting all missing values

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 907 views
  • 2 likes
  • 5 in conversation