Hi all,
Task requirement: From the dataset find the number of account entered in Accountstatus each year. I am using the code but it is giving only the year information and not the count in each year. Can you please let me know what I am missing in my code? Please see the below sample data.
data test;
input AccountKey AccountStatusKey_Current DateKey Date AccountNumber AccountStatus PreviousAccountStatus icustomerid CountAccountNumber;
56278 51 20110916 16-Sep-11 10024033 904 904 101774 1
13206 51 20110916 16-Sep-11 10005476 904 904 21397622 1
1028977 51 20110921 21-Sep-11 10508239 904 904 480014 1
873791 51 20110921 21-Sep-11 10430779 904 904 16341029 1
448436 51 20110921 21-Sep-11 10215876 904 904 21945513 1
155719 51 20110921 21-Sep-11 10069566 904 904 19463551 1
;
run;
Proc sql;
create table Entered_in_133 as
select distinct year(date) as year
from Multiple_acc_number;
quit;
You have provided us code that doesn't work. Could you please fix it?
Next, your question isn't clear. You want the count in each year, ok, count of what? Count of records? You haven't asked SQL to produce counts, you just have asked it to provide the distinct YEAR values in the data set. So I'm confused.
If you want count of records, use PROC FREQ
proc freq data=have;
tables date;
format date year.;
run;
You have provided us code that doesn't work. Could you please fix it?
Next, your question isn't clear. You want the count in each year, ok, count of what? Count of records? You haven't asked SQL to produce counts, you just have asked it to provide the distinct YEAR values in the data set. So I'm confused.
If you want count of records, use PROC FREQ
proc freq data=have;
tables date;
format date year.;
run;
Sorry for that. Yes, I want to count the number of records in each year.
data test;
input AccountKey AccountStatusKey_Current DateKey Date AccountNumber AccountStatus PreviousAccountStatus icustomerid CountAccountNumber;
datalines;
56278 51 20110916 16SEP2011 10024033 904 904 101774 1
13206 51 20110916 16SEP2011 10005476 904 904 21397622 1
1028977 51 20110921 21SEP2011 10508239 904 904 480014 1
873791 51 20110921 21SEP2011 10430779 904 904 16341029 1
448436 51 20110921 21SEP2011 10215876 904 904 21945513 1
;
run;
Your code still does not read the dates properly.
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.