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

I am trying to create a new numeric variable called "Ht_Inches" which is coming from the variable "MotherHeight"

Here is my code:

/*Convert MotherHeight to Inches*/
If MotherHeight=" " THEN Ht_Inches=" ";
ELSE Ht_Inches= (INPUT(substr(MotherHeight,2,1),5.)*12)+ 
(INPUT(substr(MotherHeight,4,2),5.));
RUN;

Here is a screenshot of what the MotherHeight data looks like:

abrice520_2-1614801743587.png

 

And here is what the log says

abrice520_1-1614801661505.png

Thank you!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

What's line 77 in your code, from the log? Please post the actual log as text, not as an image. Note that the data in the log is your data so make sure to mask any confidential information before posting which is much easier if it's text rather than an image.

For your first IF statement, the ht_inches is supposed to be numeric? In that case, it should be a period or call missing not a blank space.

If MotherHeight=" " THEN Ht_Inches=" ";

Should be:

if missing(motherHeight) then call missing(ht_inches);

 

Overall, this would be how I would do it, using SCAN instead of SUBSTR() but same idea overall:

Note that your screenshot shows a ? which is not the same as missing, so you would need to explicitly also handle that and a blank condition if that was in your data.

 

If MotherHeight in ("?", "") THEN call missing(ht_inches);

ELSE Ht_Inches= input(scan(motherHeight, 1, ":"), 8.)*12 + input(scan(motherHeight, 2, ":"), 8.);

 


@abrice520 wrote:

I am trying to create a new numeric variable called "Ht_Inches" which is coming from the variable "MotherHeight"

Here is my code:

/*Convert MotherHeight to Inches*/
If MotherHeight=" " THEN Ht_Inches=" ";
ELSE Ht_Inches= (INPUT(substr(MotherHeight,2,1),5.)*12)+ 
(INPUT(substr(MotherHeight,4,2),5.));
RUN;

Here is a screenshot of what the MotherHeight data looks like:

abrice520_2-1614801743587.png

 

And here is what the log says

abrice520_1-1614801661505.png

Thank you!

 


 

View solution in original post

2 REPLIES 2
WarrenKuhfeld
Ammonite | Level 13
If MotherHeight=" " THEN Ht_Inches=.;
Reeza
Super User

What's line 77 in your code, from the log? Please post the actual log as text, not as an image. Note that the data in the log is your data so make sure to mask any confidential information before posting which is much easier if it's text rather than an image.

For your first IF statement, the ht_inches is supposed to be numeric? In that case, it should be a period or call missing not a blank space.

If MotherHeight=" " THEN Ht_Inches=" ";

Should be:

if missing(motherHeight) then call missing(ht_inches);

 

Overall, this would be how I would do it, using SCAN instead of SUBSTR() but same idea overall:

Note that your screenshot shows a ? which is not the same as missing, so you would need to explicitly also handle that and a blank condition if that was in your data.

 

If MotherHeight in ("?", "") THEN call missing(ht_inches);

ELSE Ht_Inches= input(scan(motherHeight, 1, ":"), 8.)*12 + input(scan(motherHeight, 2, ":"), 8.);

 


@abrice520 wrote:

I am trying to create a new numeric variable called "Ht_Inches" which is coming from the variable "MotherHeight"

Here is my code:

/*Convert MotherHeight to Inches*/
If MotherHeight=" " THEN Ht_Inches=" ";
ELSE Ht_Inches= (INPUT(substr(MotherHeight,2,1),5.)*12)+ 
(INPUT(substr(MotherHeight,4,2),5.));
RUN;

Here is a screenshot of what the MotherHeight data looks like:

abrice520_2-1614801743587.png

 

And here is what the log says

abrice520_1-1614801661505.png

Thank you!

 


 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 1492 views
  • 1 like
  • 3 in conversation