- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 03-05-2021 06:13 AM
(1298 views)
I have a dataset which has a variable name city which contains more than 100 city names. How can I create tables by subsetting data according to each city for all the unique city names in city variable.
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Do you want to create datasets or tables (a report)?
For the later: sort by "city" and use proc print with by-statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Create datasets.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Ashokburnwal wrote:
Create datasets.
And why?
Mind that in about 90% of cases, splitting a dataset is not needed.
They only time in 20+ years of SAS work where I had to split a dataset was when it grew so much that sorting it in one piece cracked my quota in UTILLOC.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Ashokburnwal.,
The following code attempts to do what you require, making use of the sashelp.class data step as input and splitting it up by sex.
/* use sql to construct required data set names and output logic */
proc sql noprint;
select distinct
cat('ds_',sex)
,cat('when (', quote(sex), ') output ds_', sex)
into
:ds_names separated by ' '
,:output_logic separated by ';'
from
sashelp.class
;
quit;
options symbolgen;
/* use the macro variables created in the sql in a data step with a select statement */
data &ds_names ds_issue;
set sashelp.class;
select(sex);
&output_logic;
otherwise output ds_issue;
end;
run;
Kind regards,
Amir.