Help using Base SAS procedures

data select

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 90
Accepted Solution

data select

Hi ,

I have four fields in a table and have to create a new field called DRG..My criteria is

1. when the first character is a 'D'
2. last character is not 'A'
3. POS=21 and
4. when the above conditions are met,then the field is populated with a prefix plus the SVC minus the first character (D)
5. the prefix is based on the comp code.for comp 01 the prefix is 'J'
  and for comp 04 the prefix is 'Y'


ID svc    pos   comp

1  123    21     01
2  D234   23     01
3  D280   21     01
4  D280A  21     09
5  280A   23     09
6  D567   21     04

Output should be:

ID svc    pos   comp  DRG

1  D280   21     01   J280
2  D567   21     04   Y567

Please help us on this issue.

Thanks in Advance.


Accepted Solutions
Solution
‎09-28-2011 05:56 PM
PROC Star
Posts: 7,363

data select

data want;

  set have;

  length drg $5;

  if substr(svc,1,1) eq "D" and

   substr(reverse(strip(svc)),1,1) ne "A" and

   pos eq 21 then do;

     if comp eq "01" then drg="J"||substr(svc,2);

     else if comp eq "04" then drg="Y"||substr(svc,2);

  end;

run;

View solution in original post


All Replies
PROC Star
Posts: 7,363

data select

You could use something like:

data want;

  set have (where=(

    substr(svc,1,1) eq "D" and

    substr(reverse(strip(svc)),1,1) ne "A" and

    pos eq 21));

  length drg $5;

  if comp eq "01" then drg="J"||substr(svc,2);

  else drg="Y"||substr(svc,2);

run;

Frequent Contributor
Posts: 90

data select

Thanks Art..

In case if i want to get all the rows as below,

ID svc    pos   comp DRg

1  123    21      01
2  D234   23     01
3  D280   21     01     J280
4  D280A  21    09
5  280A   23     09
6  D567   21     04     Y280

Please let me know.

Thanks

Solution
‎09-28-2011 05:56 PM
PROC Star
Posts: 7,363

data select

data want;

  set have;

  length drg $5;

  if substr(svc,1,1) eq "D" and

   substr(reverse(strip(svc)),1,1) ne "A" and

   pos eq 21 then do;

     if comp eq "01" then drg="J"||substr(svc,2);

     else if comp eq "04" then drg="Y"||substr(svc,2);

  end;

run;

Frequent Contributor
Posts: 90

data select

Thanks Art !!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 147 views
  • 3 likes
  • 2 in conversation