BookmarkSubscribeRSS Feed
Hammis
Calcite | Level 5
I am an sql user trying to learn SAS and would appreciate it if anyone would help me with this query.

The following code I expected only to bring back the unique dates and there counts.... but running this in SAS returned a record for every observation with the year and count.

proc sql;
select year(change_date),count(*)
from customer_table
group by year(change_date);
quit;

Example result:

Year Count
2009 10000
2009 10000
2009 10000
2009 10000
...
...

What would be the correct way to write this query?
Cheers.
2 REPLIES 2
ChrisNZ
Tourmaline | Level 20
You are grouping by a fct of change_date, but change_date in not in your putput.

select year(change_date) as year, count(*)
from customer_table
group by year;

will work.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You mention "only want to bring back the date", yet you have the YEAR function coded? Interesting.

You will also want to review PROC SQL procedure discussion in the SAS documentation, available at the SAS support http://support.sas.com/ website, along with other topic-related technical papers and conference presentations on relevant topics.

Scott Barry
SBBWorks, Inc.

http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/a002473669.htm

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
  • 2 replies
  • 1185 views
  • 0 likes
  • 3 in conversation