BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kristiepauly1
Fluorite | Level 6

Hello, 

 

I am manipulating my data using the following code: 

/*Convert motherheight to height in inches*/
DATA LabAnal.study_cohort_2;
SET LabAnal.study_cohort;
IF MotherHeight = '' THEN Ht_Inches = .;
ELSE IF MotherHeight ='?' THEN Ht_Inches ='';
ELSE Ht_Inches=(INPUT(SUBSTR(MotherHeight, 1, 2), 2.)*12) + (INPUT(SUBSTR(MotherHeight, 4, 2),2.));
RUN;

^^this works great

/*Convert priorweight to a numeric variable*/
DATA LabAnal.study_cohort_2;
SET LabAnal.study_cohort;
Priorweight2 = INPUT(PriorWeight, 3.);
RUN;

^^this also works great

/*Calculate BMI*/
DATA LabAnal.study_cohort_2;
SET LabAnal.study_cohort;
IF Priorweight2= "." or Ht_inches= "." THEN BMI= ".";
ELSE BMI= (Priorweight2*703)/(Ht_Inches*2);
RUN;

^^but when I run this, it sets all the values from priorweight2, ht_inches and BMI to missing. I've tried with and without quotes around the periods in the IF statement for BMI code.  It doesn't change anything. 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

As you might have guessed, there are problems with your final step.  The main problem is here:

/*Calculate BMI*/
DATA LabAnal.study_cohort_2;
SET LabAnal.study_cohort;

You are using the wrong data set.  This step replaces LabAnal.study_cohort_2, by reading in the data rom LabAnal.study_cohort (which does not contain Priorweight2).

 

There are other, minor issues.  For example, to refer to a missing value for a numeric variable, do not use quotes.  Change the next line to:

IF Priorweight2= . or Ht_inches= . THEN BMI= .;

 

View solution in original post

3 REPLIES 3
Astounding
PROC Star

As you might have guessed, there are problems with your final step.  The main problem is here:

/*Calculate BMI*/
DATA LabAnal.study_cohort_2;
SET LabAnal.study_cohort;

You are using the wrong data set.  This step replaces LabAnal.study_cohort_2, by reading in the data rom LabAnal.study_cohort (which does not contain Priorweight2).

 

There are other, minor issues.  For example, to refer to a missing value for a numeric variable, do not use quotes.  Change the next line to:

IF Priorweight2= . or Ht_inches= . THEN BMI= .;

 

kristiepauly1
Fluorite | Level 6

I completely overlooked the DATA SET.  That was the fix. Thank You!!

japelin
Rhodochrosite | Level 12

The story changes depending on the attributes of the variables, so please provide reproducible data.

 

Without seeing the data, I can't say exactly what you're seeing.
Perhaps,

IF Priorweight2= "." OR Ht_inches= "." THEN BMI= "." ;

this statement is the problem.

 

Not . which means missing but "." which is string is stored in Priorweight2, Ht_inches, and BMI.

 

IF Priorweight2= . . or Ht_inches= . THEN BMI= . ;
would improve this point.

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1173 views
  • 0 likes
  • 3 in conversation