Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incorrect SQL generated to summarize data #41

Open
dwhollick opened this issue Apr 8, 2024 · 0 comments
Open

incorrect SQL generated to summarize data #41

dwhollick opened this issue Apr 8, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@dwhollick
Copy link

/* summarize sashelp.class with one row per age and a variable called "namelist" containing a comma delimited list of names */
Select Generate Code.

The generated DATA step works if sashelp.class is sorted by AGE:
data summarized_class;
set sashelp.class;
by age;

length namelist $200;
retain namelist;

if first.age then namelist = name;
else namelist = catx(',', namelist, name);

if last.age then output;
drop name;

run;

The generated SQL with does not create the same or desired output. The name do not get concatenated per age.
proc sql;
create table summary as
select age,
catx(", ", name) as namelist
from sashelp.class
group by age;
quit;

Also generates this log message:
WARNING: A GROUP BY clause has been transformed into an ORDER BY clause because neither the SELECT clause nor the optional HAVING
clause of the associated table-expression referenced a summary function.

Other incorrect SQL variations generated when I tweaked the comment language:

proc sql;
create table new_dataset as
select age,
catx(',', name_list) as namelist
from (select age,
catx(',', name) as name_list,
count(*) as count
from sashelp.class
group by age, name
having count > 0);
quit;

proc sql;
create table new_dataset as
select age,
catx(',', listagg(name, ',')) as namlist /* do not think listagg() is a SAS function *?
from sashelp.class
group by age;
quit;

@dwhollick dwhollick added the bug Something isn't working label Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants