BookmarkSubscribeRSS Feed
ssas
Calcite | Level 5
Hi All,
I have a file like
name postcode branch
simon me1 4en ctm
john me1 3ed rnt
tst3 me1 7fg str
hfjk me2 4kw ctm
jdk me2 6df str
jde me2 8dj rnt
.
.
.
.
;

i would like to find the no. of records for
pcode branch norecs
me1 ctm 25
me1 str 15
me2 rnt 46
....

i have used the following code

data test2(rename=(pcode1=pcode));
set test1;
* pcode is postcode;
pcode1=substr(pcode,1,3);
den=length(pcode1);
if length(pcode1)<3 then delete;
drop pcode;
run;

proc sort data=test3 nodup out=test4;
by pcode lastname branch;
run;

data test6;
set test4;
by pcode;
retain npc;
if first.pcode then do;
npc=0;
** i think some code here;
end;
npc+1;
if last.pcode then output;
run;

Now i am getting the how many records me1,me2.... but i would like to get
me1 ctm ??
me1 str ??
me1 rnt ??
me2 ctm ?
.....

Thanks in advance
Sams
4 REPLIES 4
deleted_user
Not applicable
proc sql;
create table l as select *, count(postcode) as cnt from l2 where postcode='me1' and branch='ctm' ;
run;

do the same for the remaining conditions then u will get 3 datasets then keep set for the three datasets.
deleted_user
Not applicable
Try the following code. It is simple with Proc SQL instead od datastep;

proc sql;
create table test1 as
select postcode, branch, count(*) as norecs
from test
group by postcode, branch
order by postcode, branch;
quit;

~ Sukanya E
Cynthia_sas
SAS Super FREQ
Hi:
While many good SQL solutions have been posted, do not overlook PROC FREQ or PROC TABULATE. They will both create counts and/or percents for you.

cynthia

[pre]

proc freq data=postdata;
tables pcode1*branch / list;
run;

proc tabulate data=postdata;
class pcode1 branch;
table pcode1 all,
branch*n all*n;
keylabel n=' ';
run;

[/pre]
ssas
Calcite | Level 5
Excellent,
Thanks a lot for your help.
Sukanya's and Cynth's suggestions are really helpful.
Many thanks mate(s)

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 726 views
  • 0 likes
  • 3 in conversation