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.
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: