You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/* 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;
The text was updated successfully, but these errors were encountered:
/* 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;
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;
The text was updated successfully, but these errors were encountered: