Hi,
How do i asending the oder of n number of visit coloumn ?
Example:-
DATA VAR;
INPUT Subject $ VISIT1 VISIT3 VISIT2_01 VISIT2 VISIT3_02 VISIT3_01
DATALINES;
A0001 5 6 2 3 54 2
B0001 2 4 6 5 4 5
C0001 2 4 36 5 4 2;
run;
WANT -
oderwise variables-
Subject VISIT1 VISIT2 VISIT2_01 VISIT3 VISIT3_01 VISIT3_01
Regards,
Rohit
Since you appear to only want them sorted alphabetically, your easiest approach (I think) would be to use proc sql to generate the desired ordering, and then use that info in a retain statement. e.g.:
DATA VAR;
INPUT Subject $ VISIT1 VISIT3 VISIT2_01 VISIT2 VISIT3_02 VISIT3_01;
DATALINES;
A0001 5 6 2 3 54 2
B0001 2 4 6 5 4 5
C0001 2 4 36 5 4 2
;
run;
proc sql noprint;
select name
into :names separated by " "
from dictionary.columns
where libname eq "WORK" and
memname eq "VAR"
order by name
;
quit;
data want;
retain &names.;
set var;
run;
Hi Rohit,
Were you looking for something like the following:
DATA VAR;
length Subject $8
VISIT1 $8
VISIT2 $8
VISIT2_01 $8
VISIT3 $8
VISIT3_01 $8
VISIT3_02 $8
;
INPUT Subject $ VISIT1 VISIT3 VISIT2_01 VISIT2 VISIT3_02 VISIT3_01;
DATALINES;
A0001 5 6 2 3 54 2
B0001 2 4 6 5 4 5
C0001 2 4 36 5 4 2
;
run;
Regards,
Amir.
EDIT: I just realised you've probably been given the SAS data set in that order, so you can ignore my response if that's the case.
Message was edited by: Amir Malik
The order of variables in a dataset should be irelevant - but here you go:
DATA VAR;
INPUT Subject $ VISIT1 VISIT3 VISIT2_01 VISIT2 VISIT3_02 VISIT3_01;
DATALINES;
A0001 5 6 2 3 54 2
B0001 2 4 6 5 4 5
C0001 2 4 36 5 4 2
;
run;
proc sql noprint;
select name into :SortedVarList separated by ' '
from dictionary.columns
where libname='WORK' and memname='VAR' and upcase(name) like 'VISIT%'
order by name
;
quit;
data VAR;
retain Subject &SortedVarList;
set var;
run;
Hi Rohit.
similar kind question i posted long back...
Go through bellow link,you can find some other ways...
https://communities.sas.com/thread/32930
Regards...
Sanjeev.K
As Arthur and Patrick did, You can get whatever order you want by using SQL.
DATA VAR; INPUT Subject $ VISIT1 VISIT3 VISIT2_01 VISIT2 VISIT3_02 VISIT3_01; DATALINES; A0001 5 6 2 3 54 2 B0001 2 4 6 5 4 5 C0001 2 4 36 5 4 2 ; run; proc sql noprint; select name into :SortedVarList separated by ' ' from dictionary.columns where libname='WORK' and memname='VAR' and upcase(name) like 'VISIT%' order by input(scan(name,1,'VISIT_'),best8.),input(scan(name,2,'VISIT_'),best8.) ; quit; %put &SortedVarList ; data VAR; retain Subject &SortedVarList; set var; run;
Ksharp
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.