BookmarkSubscribeRSS Feed
gnt1986
Calcite | Level 5

I have a dataset;

proc sql;

create table test as

select cat_desc

from test1;

quit;

output is

cat_desc

Eastern Region

Western Region

North

South

Eastern Region

Western Region

South

I need to assign an Id to the variables

data have;

input cat_id 1 cat_desc $2-20;

datalines;

1 Eastern Region

2 Western Region

3 North

4 South

;

run;

How can I add the cat_id in data have and apply it to  the initial dataset?

2 REPLIES 2
MeghnaMorlidhar
Calcite | Level 5

hello,

Can you tell me that in your data 'have' what you have shown in datalines is  your desired output or you want to display regions eg. eastern region by 1?(just for display : Go for Proc Format).

  • IF you have requirement of assigning a variable in proc sql in select you can use Case Expression select(cat_desc) in that use  when 'eastern region' then 1 and make everything like that and end case expression by end as Cat_id in the select clause.
  • Remain other code as it is, in that case you dont even need to create any new data.
gnt1986
Calcite | Level 5

For example if proc sql you see cat_desc Eastern Region.  However it has not cat_id.  Now look in data have.  I have replicated the cat_des and have added the cat_id.  I need to assign cat_id to cat_desc so I can use the original proc sql datastep in a program to manipulate the variables

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
  • 2 replies
  • 757 views
  • 0 likes
  • 2 in conversation