0

In the following example that produces a frequency based on a variable

proc iml;
call randseed(1);
Y = sample(2014:2020, 3000);
M = sample(1:12, 3000);
D = sample(1:31, 3000);

create Date var {Y M D};
append;
run;

data Date;
set Date;
format M z2. D z2.;
Year=put(Y, z4. -L);
Month=put(M, z2. -L);
Day=put(D, z2. -L);
drop Y M D;
run;

data Date;
set Date;
Date = catx('-', Year, Month, Day);
drop Year Month Day;
run;

proc sort data=Date; by Date; run;

proc sql;
create table Count as
select Date, count(*) as Frequency from Date
group by Date;
run;

is there a corresponding functionality in proc IML that does the same thing as the last proc sql part?

Joe
  • 62,789
  • 6
  • 49
  • 67
RavenR
  • 25
  • 5
  • 1
    `call tabulate()` ([SAS documentation](https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=imlug&docsetTarget=imlug_langref_sect519.htm&locale=en)) should be able to help you to identify unique values of the `Date` column and count observations for each value. It creates two vectors (labels and frequencies), which you should then be able to concatenate. – AlexK Apr 13 '21 at 01:00
  • Thanks! It does exactly what I want. A minor problem is that the vectors produced are row vectors. At least using create freq from freq; append from freq; They can of course be transposed but do you know a way to directly create column vectors using IML? – RavenR Apr 13 '21 at 09:17

0 Answers0