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

Hi everyone,

i have a dataset like posted below:

 

data abc;
input subjid incl1 incl2 incl3 excl1 excl2 excl3;
cards;
001 1 1 1 0 1 0
002 0 0 0 1 1 0
003 1 0 1 1 0 0
005 1 1 1 1 1 0
006 1 0 1 1 1 0
007 1 0 1 1 1 1
;
run; 

 

i want to produce an output dataset exactly like  posted below by using the above mentioned ABC dataset.

SUBJID

TYPE

RESPONSE

001

INCL1

1

001

INCL2

0

001

INCL3

1

001

exCL4

1

001

exCL5

1

001

exCL6

1

002

INCL1

1

002

INCL2

0

002

INCL3

0

002

exCL4

1

002

exCL5

0

002

exCL6

0

003

INCL1

1

003

INCL2

0

003

INCL3

1

003

exCL4

1

003

exCL5

1

003

exCL6

1

004

INCL1

0

004

INCL2

1

004

INCL3

1

004

exCL4

1

004

INCL5

1

004

INCL6

1

005

INCL1

1

005

INCL2

1

005

INCL3

0

005

exCL4

1

005

exCL5

1

005

exCL6

1

006

INCL1

1

006

INCL2

0

006

INCL3

1

006

exCL4

1

006

exCL5

1

006

exCL6

1

007

INCL1

0

007

INCL2

0

007

INCL3

0

007

exCL4

0

007

exCL5

0

007

exCL6

1

 

Any thoughts how to 

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

Hi @sahoositaram555 

 

Please try this:

proc transpose data=abc out=want (rename=(col1=response)) name=type;
	var incl1 incl2 incl3 excl1 excl2 excl3;
	by subjid;
run;

Best,

View solution in original post

4 REPLIES 4
ed_sas_member
Meteorite | Level 14

Hi @sahoositaram555 

 

Please try this:

proc transpose data=abc out=want (rename=(col1=response)) name=type;
	var incl1 incl2 incl3 excl1 excl2 excl3;
	by subjid;
run;

Best,

PeterClemmensen
Tourmaline | Level 20

Here is a data step approach

 

data want (keep= subjid type response);
   set abc;
   array a {*} incl: excl:;
   do _N_ = 1 to dim(a);
      type     = vname(a[_N_]);
      response = a[_N_];
      output;
   end;
run;
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1180 views
  • 5 likes
  • 3 in conversation