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:
And here is what the log says
Thank you!
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:
And here is what the log says
Thank you!
If MotherHeight=" " THEN Ht_Inches=.;
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:
And here is what the log says
Thank you!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.