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

Hi, I have some data that looks something like this: 

data have1;
input ID question$ subcat$ response$;
datalines;
1 Q1 a Y
1 Q1 b Y
1 Q1 c Y
1 Q2 a Y
1 Q2 b Y
1 Q2 c N
1 Q2 d N
1 Q2 e Y
2 Q1 a N
2 Q1 b Y
2 Q1 c Y
2 Q2 a N
2 Q2 b Y
2 Q2 c N
2 Q2 d N
2 Q2 e Y
;
run;

 

I need the data to look like this:

 Q1Q2
IDabcabcde
1YYYYYNNY
2NYYNYNNY

 

How do we make the response variable output to the cell? 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

How about this one ?

 

data have1;
input ID question $ subcat $ response $;
datalines;
1 Q1 a Y
1 Q1 b Y
1 Q1 c Y
1 Q2 a Y
1 Q2 b Y
1 Q2 c N
1 Q2 d N
1 Q2 e Y
2 Q1 a N
2 Q1 b Y
2 Q1 c Y
2 Q2 a N
2 Q2 b Y
2 Q2 c N
2 Q2 d N
2 Q2 e Y
;
proc report data=have1 nowd ;
    columns ('ID' id) question,subcat,response;
    define id/group ' ';
    define question/across ' ' nozero;
    define subcat/across ' ' nozero;
    define response/group ' ' nozero ;
run;

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

I don't think you can have character values Y and N underneath across variables, unless you make them numeric and formatted to produce Y and N.

 

data have1;
input ID question$ subcat$ response$;
if response='Y' then numeric_Response=1;
else numeric_response=0;
datalines;
1 Q1 a Y
1 Q1 b Y
1 Q1 c Y
1 Q2 a Y
1 Q2 b Y
1 Q2 c N
1 Q2 d N
1 Q2 e Y
2 Q1 a N
2 Q1 b Y
2 Q1 c Y
2 Q2 a N
2 Q2 b Y
2 Q2 c N
2 Q2 d N
2 Q2 e Y
;

proc format;
    value nf 1='Y' 0='N';
run;

proc report data=have1 nocompletecols;
    columns ("ID" id) question,subcat,numeric_response;
    define id/group ' ';
    define question/across;
    define subcat/across;
    define numeric_response/sum ' ' format=nf.;
run;

 

--
Paige Miller
Ksharp
Super User

How about this one ?

 

data have1;
input ID question $ subcat $ response $;
datalines;
1 Q1 a Y
1 Q1 b Y
1 Q1 c Y
1 Q2 a Y
1 Q2 b Y
1 Q2 c N
1 Q2 d N
1 Q2 e Y
2 Q1 a N
2 Q1 b Y
2 Q1 c Y
2 Q2 a N
2 Q2 b Y
2 Q2 c N
2 Q2 d N
2 Q2 e Y
;
proc report data=have1 nowd ;
    columns ('ID' id) question,subcat,response;
    define id/group ' ';
    define question/across ' ' nozero;
    define subcat/across ' ' nozero;
    define response/group ' ' nozero ;
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!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 517 views
  • 0 likes
  • 3 in conversation