BookmarkSubscribeRSS Feed
Dhana18
Obsidian | Level 7

I am trying to convert a numeric variable eg 123654 to character. i used this code 

data CDCDATA.Finaldata_CDC_ptid;
set CDCDATA.Finaldata_CDC;
patientid = put(cl_patientid,8.);
run;

th slog says;

/*Reformating numeric Patient ID to Character format*/
data CDCDATA.Finaldata_CDC_ptid;
set CDCDATA.Finaldata_CDC;
patientid = put(cl_patientid,8.);
run;

the variable did not change to character.  What is wrong with my code?

4 REPLIES 4
novinosrin
Tourmaline | Level 20

can you post your log for the program

ballardw
Super User

@Dhana18 wrote:

I am trying to convert a numeric variable eg 123654 to character. i used this code 

data CDCDATA.Finaldata_CDC_ptid;
set CDCDATA.Finaldata_CDC;
patientid = put(cl_patientid,8.);
run;

th slog says;

/*Reformating numeric Patient ID to Character format*/
data CDCDATA.Finaldata_CDC_ptid;
set CDCDATA.Finaldata_CDC;
patientid = put(cl_patientid,8.);
run;

the variable did not change to character.  What is wrong with my code?


Did you already have a variable patiend9d in the dataset? If so you cannot change the TYPE once it is created. You likely have a note like this:

NOTE: Character values have been converted to numeric values at the places given by:
      (Line):(Column).

That means you attempted to assign a character value (the put) into a numeric variable and was converted so that the existing numeric variable could hold the new value, assuming it would convert.

 

 

Question: Why the concern over it being character or numeric?

Dhana18
Obsidian | Level 7
I did not get any note.
ballardw
Super User

@Dhana18 wrote:
I did not get any note.

So, how do you know it did not "change to character"?

Show use your log from running your code. Copy from the log and paste into a code box opened using the forum's {I} icon. Include all the notes at the end of the data step.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 734 views
  • 0 likes
  • 3 in conversation