BookmarkSubscribeRSS Feed
gahlot1999
Fluorite | Level 6

Hi Community,

My source data is - 

gahlot1999_0-1652732566507.png

And I want this output - 

gahlot1999_1-1652732645715.png

Any easy way to do this in proc sql?

2 REPLIES 2
gahlot1999
Fluorite | Level 6
I want seq variable to get change when unscheduled visit is there...otherwise it should do +1 always.
mkeintz
PROC Star

I imagine one could develop some way to torture SQL into submission for this task - although I am unable to see how.

 

But why?  The DATA step cares about the sequence of incoming records, while SQL doesn't - that's SQL's advantage/disadvantage. True, in SQL you could detect "Screen","Week 1", "Week 2", "Week 3" and "End of study" to generate codes, 1,2,3,4 and 5. That's assuming you want those codes for each visit type.

 

But what about "Unscheduled?"   Could such a record fall between "Week 2 and "Week 3", implying codes of 3.1, 3.2, etc instead of 4.1, 4.2?  How would SQL determine where the Unscheduled appears?  And then you have demonstrated the problem of multiple Unscheduled records.  Which one gets 4.1 and which gets 4.2 (assuming you even know they should be a 4.x to begin with).

 

This data step is untested, in the absence of sample data in the form of a working data step:

 

data want;
  set have;
  by id;
  if seq='Unscheduled' then seq+0.1;
  else seq=ceil(seq+0.01);
  if first.id then seq=1;
run;

Of course, this assumes you never have more then 9 consecutive "Unscheduled" records.

--------------------------
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

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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 426 views
  • 0 likes
  • 2 in conversation