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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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.

View solution in original post

5 REPLIES 5
art297
Opal | Level 21

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.

data_null__
Jade | Level 19

GROUPFORMAT?

data temp;
   input bankname $ brnum cntyname &$30.;
  
cards;
Bofa 0 Mecklenburg
bofa 1 Orange
Bofa 2 Ventura
Bofa 3 Amameda
welch 0 Contra Costa
Welch 1 Los Angeles
WelCh 3 Tulare
ChaSe 0 Kern
Chase 1 Shasta
Chase 2 Santa Cruz
chase 3 Yolo
;;;;
   run;


data new;
   set temp;
   format bankname $upcase.;
  
by bankname groupformat notsorted;
  
retain totbr;
   if first.bankname then do;
   totbr =
0;
  
end;
  
if last.bankname then output;
  
run;
proc print;
  
run;
art297
Opal | Level 21

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.

hsharmas
Fluorite | Level 6

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

hsharmas
Fluorite | Level 6

Ohh I am sorry Arthur already indicated that approach!

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!

How to Concatenate Values

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.

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
  • 5 replies
  • 714 views
  • 0 likes
  • 4 in conversation