- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi ,
I am getting duplicate rows in data. The result is correct but it's generating same rows multiple times.
The code is :
proc sql;
create table final as
select month_year , count(distinct ccsid) as unique_visitor
from login_old
where ccsid ne ' '
group by month_year;
quit;
I am getting result as below :
2020-04-01 12989
2020-04-01 12989
2020-04-01 12989
2020-04-01 12989
2020-05-01 17894
2020-05-01 17894
2020-05-01 17894
2020-05-01 17894
I want only one row for each result. Duplication is not needed.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
select DISTINCT month_year , count(distinct ccsid) as unique_visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You usually don't see that with the day component though, but it's the only reason I can think of for SQL to behave this way. SQL aggregation does not honour SAS formats. You need to apply the format instead.
proc sql;
create table final as
select put(t1.month_year, yymmn6.) as month_year , count(distinct ccsid) as unique_visitor
from login_old t1
where ccsid ne ' '
group by put(t1.month_year, yymmn6.);
quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
error : Numeric format YYMMN in put function requires a numeric argument.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
select DISTINCT month_year , count(distinct ccsid) as unique_visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Check the field month_year for leading spaces.
Or invisible characters like TAB ('09'x) CR ('0D'x) LF ('0A'x) non-breaking space ('A0'x) null ('00'x)
Or some of the hyphens are not hyphens but other character like en-dash or em-dash.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You sure you didn't include some third variable in the SELECT list of variables?
If you include non-grouping and non-aggregate values then SAS will remerge the aggregate values back on the results.
SAS will include a note in the log:
1512 proc sql; 1513 select sex, mean(age) as mean_age, height 1514 from sashelp.class 1515 group by sex 1516 ; NOTE: The query requires remerging summary statistics back with the original data.