BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
raveena
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

4 REPLIES 4
art297
Opal | Level 21

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;

raveena
Obsidian | Level 7

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

art297
Opal | Level 21

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;

raveena
Obsidian | Level 7

Thanks Art !!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1011 views
  • 3 likes
  • 2 in conversation