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.

 

 

 

 

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 603 views
  • 2 likes
  • 5 in conversation