(Given Data)
PT Gender
101 Male
102 M
103 Female
104 MALE
105 f
(Given Data)
studyname - GSK101A2
site no : G101
SEX - M OR F
Domain - DM
Required o/p : (i need the output like this)
STUYID DOMAIN USUBJID SUBJID SEX
GSK101A2 DM GSK101A2-G101-101 101 M
GSK101A2 DM GSK101A2-G101-102 102 M
GSK101A2 DM GSK101A2-G101-103 103 F
GSK101A2 DM GSK101A2-G101-104 104 M
GSK101A2 DM GSK101A2-G101-105 105 F
/*The data items could be input using macro variables to make this flexible.*/
data Want ;
set Have (rename=( pt=SUBJID)); *the dataset with PT and gender ;
STUYID= "GSK101A2";
DOMAIN= "DM" ;
SiteNo = "G101" ;
length USUBJID $ 17;
drop siteno gender;
USUBJID= catx("-",stuyid,siteno, subjid);
SEX= substr(upcase(gender),1,1);
run;
proc print data=reqdop ;
var stuyid domain usubjid subjid sex;
run;
@Akhilaaron07 wrote:
(Given Data)
studyname - GSK101A2
site no : G101
SEX - M OR F
Domain - DM
Are these name/value pairs in a dataset, or did you mistakenly represent the data in transposed form?
DATA want;
length STUDYID $8 DOMAIN $2 USUBJID $17 SEX $1;
set have;
array chars STUDYID DOMAIN SITENO PT SEX;
do over chars;
chars=strip(upcase(chars));
end;
SUBJID=strip(put(PT,best.));
if cmiss(STUDYID,SITENO,SUBJID) ne 0 then put 'E' 'RROR: Missing unexpected variables encountered' STUDYID= SITENO= SUBJID=;
else USUBJID=catx('-',STUDYID,SITENO,SUBJID);
SEX=ifc(SEX^='',substr(SEX,1,1),'');
RUN;
- Cheers -
data have;
infile cards length=len;
input have $varying400. len;
if have=:'PT' then id+1;
n+1;
if anydigit(have)=1 then do;
subjid=scan(have,1,' ');sex=upcase(char(scan(have,2,' '),1));
end;
if lowcase(scan(have,1,' '))='studyname' then studyid=scan(have,-1,' ');
if lowcase(scan(have,1,' '))='site' then siteid=scan(have,-1,' ');
if lowcase(scan(have,1,' '))='domain' then domain=scan(have,-1,' ');
if not missing(coalescec(subjid,sex,studyid,siteid,domain));
drop have;
cards;
(Given Data)
PT Gender
101 Male
102 M
103 Female
104 MALE
105 f
(Given Data)
studyname - GSK101A2
site no : G101
SEX - M OR F
Domain - DM
;
proc sort data=have;by id descending n;run;
data want;
update have(obs=0) have;
by id;
if not missing(subjid) then output;
run;
data want;
set want;
usubjid=cats(studyid,'-',siteid,'-',subjid);
run;
proc sort data=want;by id n;run;
/*The data items could be input using macro variables to make this flexible.*/
data Want ;
set Have (rename=( pt=SUBJID)); *the dataset with PT and gender ;
STUYID= "GSK101A2";
DOMAIN= "DM" ;
SiteNo = "G101" ;
length USUBJID $ 17;
drop siteno gender;
USUBJID= catx("-",stuyid,siteno, subjid);
SEX= substr(upcase(gender),1,1);
run;
proc print data=reqdop ;
var stuyid domain usubjid subjid sex;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.