Hi,Everyone,
I have a question about how to create a new variable which is in the reverse order of another one;
for instance ,this is the dataset,
NAME SALARY
JACK 100
LUCY 200
MIKE 300
KATE 400
What I need is to create a new variable say "SALARY_REVERSE" to make the dataset looks like the follows
NAME SALARY SALARY_REVERSE
JACK 100 400
LUCY 200 300
MIKE 300 200
KATE 400 100
Thank you very much!
Sounds silly
proc sort data=have out=haver; by descending salary ; run;
data want;
set have;
set haver(keep=salary rename=salary=reverse_salary);
run;
Sounds silly
proc sort data=have out=haver; by descending salary ; run;
data want;
set have;
set haver(keep=salary rename=salary=reverse_salary);
run;
Salary_Reverse=500-Salary;
Hi,
Let's say the dataset name is test, my solution is below
*Label Observation Number;
data test;
set test;
N = _N_;
run;
*Reverse the Order;
proc sort data = test out = test_reverse; by decending _N_;run;
*Relabel Observation Number;
data test_reverse;
set test_reverse;
N=_N_;
run;
*Merge the two datasets;
data test_combine;
set test test_reverse;
by N;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.