BookmarkSubscribeRSS Feed
saza
Quartz | Level 8

Was asked to make many character variables into numeric ones but cannot seem to run my code. The question is asking me to make a new variable called "HTC_STATn" which equals 1 is there new patients as the value and 0 is there is established patients.

 

When I run this code the dataset is blank

data temp2;
set demomed;
If htc_stat= "established patient" then HTC_STATn="0";
If htc_stat= "new patient" then HTC_STATn= "1";
run;
data temp2;
set demomed;
If htc_stat= "established patient" then HTC_STATn="0";
If htc_stat= "new patient" then HTC_STATn= "1";
If htc_stat= "transfer patient" then HTC_STATn= "1";
If hepther = "y" HEPTHERn= "1";
If hepther = "n" HEPTHERn= "0";
If Htype = "hemophilia a" then HTYPEn = "0";
If Htype = "hemophilia b" then HTYPEn = "1";
If Hlevel = 'mild' then Hleveln = "0";
If Hlevel = 'moderate' then Hleveln = "1";
If Hlevel = 'severe' then Hleveln = "2";
run;

 

5 REPLIES 5
StatDave
SAS Super FREQ

The CtoN macro is a general tool for character to numeric conversion. Your specific code just creates a new character variable with character values "0" and "1". If you want it to be numeric, remove the quotes:

If htc_stat= "established patient" then HTC_STATn=0;
If htc_stat= "new patient" then HTC_STATn= 1;

 

saza
Quartz | Level 8
I did there but I still am getting a syntax error stating that i'm missing symbols within if/then statements?
Tom
Super User Tom
Super User

The question is asking me to make a new variable called "HTC_STATn" which equals 1 is there new patients as the value and 0 is there is established patients.

SAS return a 1 or 0 as the result of a boolean expression.  So just use:

 

data temp2;
  set demomed;
  HTC_STATn = (htc_stat= "new patient");
run; 

 

ballardw
Super User

@saza wrote:

 

When I run this code the dataset is blank


Show us the results of running Proc Contents on the data set DEMOMED.

If the result data set is blank that strongly suggests that the source data set was as well.

a bit like :

HTC_STATn="0";

Does not assign a numeric value to HTC_STATn but a character value of "0". A numeric assignment would look like

HTC_STATn= 0 ;

Also, you want to be very careful about = with character variables. "Mild" is not equal to "mild" so make sure that case is considered.

 

 

 

 

 

 

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
  • 5 replies
  • 809 views
  • 2 likes
  • 5 in conversation