BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Akhilaaron07
Calcite | Level 5

(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

1 ACCEPTED SOLUTION

Accepted Solutions
john_robinson
SAS Employee

/*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;

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

@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?

Oligolas
Barite | Level 11
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 -

Ksharp
Super User
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;
john_robinson
SAS Employee

/*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
Calcite | Level 5
Guys Finally i got the output i am not removing it, If any one in Future happens to Stumble up on it.

data dm1;
input PT Gender$;
datalines;
101 Male
102 M
103 Female
104 MALE
105 f
;
run;

Data DM;
STUDYID="GSK101A2";
DOMAIN="DM";
SITEID="G101";
length USUBJID $20. ;
set dm1(rename= (PT=SUBJID));
USUBJID= catx("-",STUDYID,SITEID,SUBJID);
If Gender in('M','Male','MALE') then SEX='M';
else SEX='F';
drop Gender;
run;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1164 views
  • 3 likes
  • 5 in conversation