BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Sandeep77
Lapis Lazuli | Level 10

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;
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller
Sandeep77
Lapis Lazuli | Level 10

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;

PaigeMiller
Diamond | Level 26

Your code still does not read the dates properly.

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 3 replies
  • 353 views
  • 1 like
  • 2 in conversation