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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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