BookmarkSubscribeRSS Feed
rajeshalwayswel
Pyrite | Level 9
DATA HAVE;
INPUT VISIT $10. VISITNUM;
CARDS;
VISIT 1      1
VISIT 1      1
VISIT 1      1
VISIT 1      1
UNSCH        999
UNSCH        999
RUN;

Required Output:

VISIT        VISITNUM   VISIT_                            VISITNUM_
VISIT 1      1                 VISIT 1                                 1
VISIT 1      1                 VISIT 1   		                  1
VISIT 1      1                 VISIT 1 			          1
VISIT 1      1                VISIT 1  		                  1
UNSCH        999       UNSCH VISIT 1 999.001      999.001
UNSCH        999       UNSCH VISIT 1 999.002      999.002
4 REPLIES 4
mkeintz
PROC Star

What are the rules you want to implement?

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

--------------------------
rajeshalwayswel
Pyrite | Level 9
In new variables Visit_, Visitnum_.
mkeintz
PROC Star

@rajeshalwayswel wrote:
In new variables Visit_, Visitnum_.

That's not a rule.  It's an example.  You post

VISIT        VISITNUM   VISIT_                            VISITNUM_
VISIT 1      1                 VISIT 1                                 1
VISIT 1      1                 VISIT 1                     1
VISIT 1      1                 VISIT 1           1
VISIT 1      1                VISIT 1                    1
UNSCH        999       UNSCH VISIT 1 999.001      999.001
UNSCH        999       UNSCH VISIT 1 999.002      999.002

 

It doesn't answer these questions:

  1. Do you only have two types of records?
    1. type 1:   VISIT="VISIT 1",  and VISITNUM=1
      and
    2. type 2:  VISIT=UNSCH and VISITNUM=999
  2. If you really only have these two types, it appears that for type 1,   VISIT_=VISIT  and VISITNUM_=VISITNUM, right?

  3. But for VISITNUM=999, you have VISITNUM_ as a sequence (999.001,999.002).  If you have subsequent "VISIT 1" records, followed by another 999 record, does that record become 999.003, or do you restart at 999.001?
  4. How does UNSCH become UNSCH VISIT 1?  Does the "VISIT 1" part come from retaining the preceding "VISIT 1" value  (i.e. the most recent non-UNSCH value for VISIT?), or is it a constant value that you always insert in such a case?

 

 

 

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

--------------------------
rajeshalwayswel
Pyrite | Level 9
When visit=UNSCH value I need to retain before value and concatenate it by "UNSCH", Visit variable value

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 543 views
  • 1 like
  • 2 in conversation