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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1384 views
  • 1 like
  • 3 in conversation