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

So I have a file that has the following data:

User,

Session

 

What I want to happen is I want to list a user and then for each of the three sessions have a "Y" or "N" if they attended.  So something like this:

 

User Session 1 Session 2 Session 3
Harry Crumb Y N Y

 

I have tried this code, however I am getting three separate lines generated.  So I am trying to figure out how to put everything on the 1 line.

 

CASE
when Session in ('Session_1') then ('Y)
else ('N')
end as Session_1,

CASE
when Session in ('Wave_2') then ('Y')
else ('N')
end as WAVE_2,

CASE
when Session in ('Session_3') then ('Y')
else ('N')
end as Session_3

 

I was trying to search for the answer, but I am not sure what this type of syntax is called.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

In a first data step, add a variable x that contains just a 'Y'.

Then transpose with

by user;

id session;

var x;

In a final data step, replace all missing character variables with 'N'.

This method is data-driven , no explicit coding for values is needed.

Note that for this to work, session must contain valid SAS names.

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

In a first data step, add a variable x that contains just a 'Y'.

Then transpose with

by user;

id session;

var x;

In a final data step, replace all missing character variables with 'N'.

This method is data-driven , no explicit coding for values is needed.

Note that for this to work, session must contain valid SAS names.

IgawaKei29
Quartz | Level 8

Thank you that was a big help.  I have only used PROC Transpose a few times, so I didn't think of using it here.  I will be using this again I'm sure!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 2 replies
  • 845 views
  • 1 like
  • 2 in conversation