BookmarkSubscribeRSS Feed
Denali
Quartz | Level 8

I've got a dataset imported from SPSS. The smoking status from patients is coded as "smoke" variable. And it has 3 categories "Current smoker", "Ex smoker" and "Non-smoker". I wanted to code this categorical variable into 0, 1, 2 so I wrote below code. However, it did not work. It is showing "." in each column.

 

if smoke='Current smoker' then smoke1=2;
else if smoke='Ex smoker' then smoke1=1;
else if smoke='Non-smoker' then smoke1=0;
else if smoke='No Answer' then smoke1=.;

2 REPLIES 2
Astounding
PROC Star

This section of the program looks OK.  The problem might lie in another section of the program, or it might lie in the data. 

 

Example:  The data actually contains all uppercase values for SMOKE.

 

Example:  The number of characters in SMOKE is actually less than 10 (for whatever reason).

 

Example:  The DATA step that contains this code forgot to use a SET statement to read in the data source.

 

The steps you can take to help:

 

Run a PROC FREQ on the variable SMOKE to verify the actual values it contains.

 

Post the log from your DATA step (not the program).  That will contain key results to help diagnose the source of the problem.

ballardw
Super User

Please run Proc Contents on that data set and share the results for the smoke variable.

 

When you say you get . it may mean that smoke is already numeric and you perhaps are seeing a Format applied to an existing numeric value.

Or try:

 

proc freq data=<your data set name>;

   tables smoke;

   format smoke best.;

run;

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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