DATA Step, Macro, Functions and more

Merge both character and numeric variables

Accepted Solution Solved
Reply
Contributor
Posts: 25
Accepted Solution

Merge both character and numeric variables

 

CODE:
data trial; /*name of the new dataset*/ attrib new length=$4; /*name of the variable to which calculated value is assigned*/ set database; /*original dataset*/ by SUBJECT; /*sorting by SUBJECT, which is UNIQUE and with no duplicates*/ /*Calculating the new variable by using the following condition*/ if (upcase (AUNIT) eq 'U/L' AND upcase (AVALUE) > 2000) or (upcase (BVALUE) eq 'BILIRUBIN LEVEL' AND upcase (ASUNIT) eq 'MG/DL' AND upcase (AVALUE) > '10') or (upcase (GRAFT) eq 'Yes') then new="Yes"; else new="No"; run; Proc sort data=trial; by SUBJECT; run;



Hi,

IF Condition with few numeric and character types are to be considered, and out put to be displayed should be a character Value (YES or NO) which is resulting in the following NOTE.
NOTE: Character values have been converted to numeric values at the places given by: (Line)Smiley SadColumn).
70:37
NOTE: Numeric values have been converted to character values at the places given by: (Line)Smiley SadColumn).
70:147 71:83 72:78 72:147
What could be possible solution?
1. Convert the numeric values to character values?
2. Doing #1, is leading to another NOTE which says that the variable is both in character and numeric.
Any suggestions?
Thank you,
 

Regards,
Nasya

Accepted Solutions
Solution
a month ago
Regular Contributor
Posts: 167

Re: Merge both character and numeric variables

if avalue is numeric why do you have: upcase (AVALUE) > '10'. Note that this is inconsistent with this other piece of code where there are no quote marks: upcase (AVALUE) > 2000. First remove the use of "upcase", if it's numeric you shouldn't be using this. And remove the quote marks in the first bit of code.

--------------
blog: papersandprograms.com

View solution in original post


All Replies
Regular Contributor
Posts: 167

Re: Merge both character and numeric variables

to make the note go away, treat the char variable as char and the numeric variable as numeric. You just need to double check what your variables are and then treat them accordingly. There is certainly an issue with this bit "upcase (AVALUE) > 2000", because you are saying avalue is char but treating it as numeric. First convert it to numeric, as you say

--------------
blog: papersandprograms.com
Contributor
Posts: 25

Re: Merge both character and numeric variables

Posted in reply to PaulBrownPhD
Thanks for your response. AVALUE is in numeric only, no conversion is made. Other values are Character in type. The new variable is a character too- displaying output as Yes or No.
Combining Numeric and Character values and displaying output as Character is possible or do we have to convert all the variables to Character?
Solution
a month ago
Regular Contributor
Posts: 167

Re: Merge both character and numeric variables

if avalue is numeric why do you have: upcase (AVALUE) > '10'. Note that this is inconsistent with this other piece of code where there are no quote marks: upcase (AVALUE) > 2000. First remove the use of "upcase", if it's numeric you shouldn't be using this. And remove the quote marks in the first bit of code.

--------------
blog: papersandprograms.com
Contributor
Posts: 25

Re: Merge both character and numeric variables

Posted in reply to PaulBrownPhD
Worked. Thanks a lot.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 68 views
  • 0 likes
  • 2 in conversation