BookmarkSubscribeRSS Feed
bncoxuk
Obsidian | Level 7
I have a data like the one below. For each person (with ID), he went to either cinema (1,2) at different time. Just ignore the variable date. I want to know how a program can be developed in the DATA step to resolve the following question:

Get a summary for each person (ID) in terms of their frequency of visit to the two cinemas, using only the DATA step?

I want to program to get the results

Cinema ID Date
1 1 11/02/2007
1 2 11/02/2007
1 2 15/04/2007
1 2 20/06/2007
1 3 14/11/2007
2 1 05/01/2007
2 1 12/05/2007
2 2 08/08/2007

The result should look like this:
Cinema ID Freq
1 1 1
1 2 3
1 3 1
2 1 2
2 2 1
9 REPLIES 9
Cynthia_sas
Diamond | Level 26
Hi:
This task seems tailor-made for PROC FREQ. Is there a reason you want a DATA step when PROC FREQ will create an output data set with the exact information you need???

Just curious.

cynthia
bncoxuk
Obsidian | Level 7
Hi, I got a dataset which requires the use of DATA step to handle it. Better to use DATA step rather than any procedure.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Again - why would you need/want to "require" a DATA step, if the task can be completed in fewer SAS programming statements and possibly more efficiently?

And, so, with a DATA step, you must first sort your data, and then use BY GROUP PROCESSING to identify FIRST. and LAST. conditions for your defined BY variable list and the .

Explore the available DOC -- see the GOOGLE search below.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

data step by group processing site:sas.com
bncoxuk
Obsidian | Level 7
Thanks, I will try to get a solution using first. and last. Cheers.
rtritz
Calcite | Level 5
While I agree that proc freq would be the logical way to go, if you must use a data step this should get you started.

data cinema;
input cinema id date ddmmyy10.;
datalines;
1 1 11/02/2007
1 2 11/02/2007
1 2 15/04/2007
1 2 20/06/2007
1 3 14/11/2007
2 1 05/01/2007
2 1 12/05/2007
2 2 08/08/2007
;
run;

data cinema2 (drop=date total);
retain total;
set cinema;
by cinema id notsorted;

if first.id then total = 0;
total+1;
count = total;
if last.id;
run;

Rich
Peter_C
Rhodochrosite | Level 12
Data ;
do freq = 1 by 1 until( last.id ) ;
set your_data ;
By cinema id ;
End;
Run;
Almost as short as PROC FREQ
Kevin_Graduate
Calcite | Level 5
Oh dear, such a neat and clever approach.

Any resource to recommend?
Peter_C
Rhodochrosite | Level 12
Kevin

you are the resource
(just like all other posters)

here is the resource
(just like a lot of other discussion forums)

how long the list of SAS-lists?
longer than we can imagine!

What it used to be, was bit list server (circa 1986 ++ )
later, sas-l on mirrored mail servers
and "use net"

later google bought comp,soft-sys.sas
. . . . or ... brought comp.soft-sys.sas into google groups
and a (loose) gateway between was maintained

but, I think, I heard it's no longer effective
(call it defective?)

and we fragment the discussions some more

volume on SAS-L used to be around 80 messages per day (I could almost cope)
(before support.sas.com/forums)
(before spam)

possible we now have 80+ discussion channels

fragmentation is not always bad

but does make it difficult - - - to
keep up
to date
sas_
Fluorite | Level 6
try this:

proc freq data=cinema;
tables cinema*id/norow nocol nopercent nocum out=b;
run;
proc print;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 2237 views
  • 0 likes
  • 7 in conversation