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.
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;
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;
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
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;
Thanks Art !!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.