BookmarkSubscribeRSS Feed
sammydouglas
Calcite | Level 5

Hello,

 

I have a data set with the variable Order_Type and it has numeric values of 1 2 and 3. 

I need to take those numeric values and have them changed into different words. 

 

So Order_Type 1 should be labeled as ‘In-Store’ 

Order_Type 2 should be labeled as ‘Catalogue’

Order_Type 3 should be labeled as ‘Web’

 

I keep getting errors when trying this: 

 

data orders;

set BUS_4024.dly_orders;

if Order_Type = 1 then Order_Type = "In-store";

run;

 

Warnings say "Invalid numeric data, 'In-store'" for every line. 

 

Im not that great with SAS but have been trying my best. Really appreciate any help, thanks!

3 REPLIES 3
sammydouglas
Calcite | Level 5
nevermind, i read the question wrong! Apparently I need to create a new variable Order_Type_Labels and have that variable list the words according to the number.
Tom
Super User Tom
Super User

Look into how to use formats.

proc format ;
  value Order_Type 1=‘In-Store’  2=‘Catalogue’ 3=‘Web’;
run;

Then you can have it display the descriptive text without changing the data.

proc freq data=have ;
  tables order_type;
  format order_type order_type.;
run;
ballardw
Super User

General hint: SAS data sets have exactly two data types: numeric and character. The type, once set, cannot change. Attempting to assign a character value to numeric will generally fail unless your character value happens to look numeric: '123.45' for instance. At which point SAS will attempt to do what you want but will generate a note in the log about conversion of character to numeric (or vice versa). But if the value cannot by any stretch of the imagination be numeric such as "In-store" then it fails and you get the result you encountered.

 

One nice thing about SAS though is that you can use a custom format to display desired text based on a numeric value or range of values.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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