hello,
I want to output observation "Visit" for all subjects.
data have:
subject | visit |
001 | monday |
001 | friday |
002 | monday |
003 | monday |
003 | tuesday |
003 | wednesday |
data want:
subject | visit |
001 | monday |
001 | tuesday |
001 | wednesday |
001 | thursday |
001 | friday |
002 | monday |
002 | tuesday |
002 | wednesday |
002 | thursday |
002 | friday |
003 | monday |
003 | tuesday |
003 | wednesday |
003 | thursday |
003 | friday |
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;
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;
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.