BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sakthivel_Saran
Calcite | Level 5

This is my code:

 

data amt2.value_labels;
set amt2.assignment2;
if gender = 0 then gender = 'Male';
run;

 

This converted all the values with zero to .

 

Error Message:

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
64:29
NOTE: Invalid numeric data, 'Male' , at line 64 column 29.
storeid=1 hlthfood=0 size=2 org=2 custid=1 gender=. shopfor=1 veg=0 style=1 usecoup=3 week=1 seq=4 carry=0 coupval=4 amtspent=215.28
 
Any Solutions?.
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

You are trying to assign a character value to a numeric variable, that is why you get an error. Write the value 'Male' to a vairble suct as genderc and yo will be fine

 

data amt2.value_labels;
set amt2.assignment2;
if gender = 0 then genderc = 'Male';
run;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

You are trying to assign a character value to a numeric variable, that is why you get an error. Write the value 'Male' to a vairble suct as genderc and yo will be fine

 

data amt2.value_labels;
set amt2.assignment2;
if gender = 0 then genderc = 'Male';
run;
ballardw
Super User

Or skip the new variable entirely.

I am guessing that a value of 1 may be female. If different change the vale in proc format code from 1 to the appropriate value.

If you have more values for gender then add additional code values.

 

proc format library=work;
value mygender
0= 'Male'
1= 'Female'
;

proc print data=amt2.assignment2;
   var gender;
   format gender mygender.;
run;

Custom formats can be used to display different text for the same variable in different places. For instance you may have a need for a display of single letter for gender, so you make a different named format (the first word after VALUE above) and only have M and F as values, or you want to display something like "** Male **", a different format and use. Groups of codes can also be assigned to single

 

display value that will be honored by most procedures.

 

Especially with large data sets creating a new format may be much more time efficient than duplicating a data set just to get a different display.

And you can use formats for character variables in a similar way.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3230 views
  • 0 likes
  • 3 in conversation