BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
HitmonTran
Pyrite | Level 9

hello,

 

I want to output observation "Visit" for all subjects.  

data have:

subjectvisit
001monday
001friday
002monday
003monday
003tuesday
003wednesday

 

data want:

subjectvisit
001monday
001tuesday
001wednesday
001thursday
001friday
002monday
002tuesday
002wednesday
002thursday
002friday
003monday
003tuesday
003wednesday
003thursday
003friday
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You need a list of subjects and a list of visits.  

Let's assume the list of subjects comes from the dataset you already have.

What is the source for the list of visits?

Perhaps something like this:

data visits;
  input visit $20.;
cards;
monday
tuesday
wednesday
thursday
friday
;

So a simple join like this should generate what you want.

proc sql;
create table want as select *
  from (select distinct subject from have)
     , vists
  order by subject, visit
;
quit;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

You need a list of subjects and a list of visits.  

Let's assume the list of subjects comes from the dataset you already have.

What is the source for the list of visits?

Perhaps something like this:

data visits;
  input visit $20.;
cards;
monday
tuesday
wednesday
thursday
friday
;

So a simple join like this should generate what you want.

proc sql;
create table want as select *
  from (select distinct subject from have)
     , vists
  order by subject, visit
;
quit;
mkeintz
PROC Star

You apparently want a Cartesian crossing of subject and visit (although you don't have Thursday in your sample data, but do have it in your desired output.  Use the "completetypes" option of PROC SUMMARY:

 

data have;
  input subject visit :$9.    ; 
  format subject z3.;
datalines;
1 Monday
1 Friday
2 Monday
3 Monday
3 Tuesday
3 Wednesday
run;

proc summary data=have completetypes nway;
  class subject visit ;
  output out=want (drop=_type_);
run;

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 823 views
  • 1 like
  • 3 in conversation