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.
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.
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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.