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

Hi. 

I would like to record variable dynamically (I don’t know how many unique values) from:

Blue sky

white snow

etc

to

value1

value2

value3

etc.

 

thank you.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

A format is probably your best bet. Does the order matter? Do you need to keep consistency between the variables, ie value1 is always Blue Sky. 

 

*get list of unique values;
proc freq data=sashelp.cars noprint;
table origin / out=unique_origin;
run;

*create data set for proc format;
data origin_fmt;
set unique_origin;
start=origin;
label = catt("Value", put(_n_, 8. -l));
fmtname='origin_fmt';
type='C';
run;

*create fomrat;
proc format cntlin=origin_fmt;
run;

*apply format;
data remapped;
set sashelp.cars;
Origin_New = put(origin, $origin_fmt.);
run;

Similar ID to this I suppose:

https://gist.github.com/statgeek/fd94b0b6e78815430c1340e8c19f8644

 


@Zula wrote:

Hi. 

I would like to record variable dynamically (I don’t know how many unique values) from:

Blue sky

white snow

etc

to

value1

value2

value3

etc.

 

thank you.

 

 


 

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20
What's your question?
Reeza
Super User

A format is probably your best bet. Does the order matter? Do you need to keep consistency between the variables, ie value1 is always Blue Sky. 

 

*get list of unique values;
proc freq data=sashelp.cars noprint;
table origin / out=unique_origin;
run;

*create data set for proc format;
data origin_fmt;
set unique_origin;
start=origin;
label = catt("Value", put(_n_, 8. -l));
fmtname='origin_fmt';
type='C';
run;

*create fomrat;
proc format cntlin=origin_fmt;
run;

*apply format;
data remapped;
set sashelp.cars;
Origin_New = put(origin, $origin_fmt.);
run;

Similar ID to this I suppose:

https://gist.github.com/statgeek/fd94b0b6e78815430c1340e8c19f8644

 


@Zula wrote:

Hi. 

I would like to record variable dynamically (I don’t know how many unique values) from:

Blue sky

white snow

etc

to

value1

value2

value3

etc.

 

thank you.

 

 


 

Reeza
Super User
Note that I edited your question title as it was too generic. Please use a more descriptive title in the future.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 803 views
  • 1 like
  • 3 in conversation