Hello all,
data temp;
input bankname brnum cntyname
cards;
Bofa 0 Mecklenburg
Bofa 1 Orange
Bofa 2 Ventura
Bofa 3 Amameda
Welch 0 Contra Costa
Welch 1 Los Angeles
Wlech 3 Tulare
Chase 0 Kern
Chase 1 Shasta
Chase 2 Santa Cruz
chase 3 Yolo
;
run;
data new;
set temp;
retain totbr;
attrib totbr informat=8. format 12.
by bankname;
if first.bankname then do;
totbr = 0;
end;
if last.bankname then output;
run;
I would like to have the brnum '0' information on the dataset than having the last record info.
I want to use first. and last. statements calculate the totbr, otherwise I want to have the first record of bankname(brnum=0) info onthe new dataset.
Would any one help on this?
Thanks in advance.
I'm surprised that no one has responded. If your data really have mixed case (e.g., chase and Chase), you should pre-process the data to convert bankname to uppercase.
Then, to do what you want, sort by bankname descending brnum, then use the code you indicated.
I'm surprised that no one has responded. If your data really have mixed case (e.g., chase and Chase), you should pre-process the data to convert bankname to uppercase.
Then, to do what you want, sort by bankname descending brnum, then use the code you indicated.
GROUPFORMAT?
DN: I agree with using groupformat (which, I admit, I didn't know about), but I still think that the OP wants to sort by bankname descending brnum
Simply using the groupformat could cause problems if the wrong cases happen to be located somewhere in the middle of that combination.
I think saslovethemost wrote that as an example and forgot the specifics. Anyways, a quick and dirty approach would be:
sort the data first by bankname and then by descending brname and use the same code as you are using currently
proc sort data = temp;
by bankname descending brname ;
run;
and your first. and last. calculation.
Regards,
Somi
Ohh I am sorry Arthur already indicated that approach!
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 how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.