I need to dynamically to create location datasets with 100 observations for each location.The idea is that they should be updated locally by editing.
I first create a list (macro called name1.) with the names of the files. Then create the design of the table.
I can not get it to work in the last part where I need to filter the observations onlovation i.e. I need the right and only 100 observations in each dataset.
Hope you can help.
Here is some code:
proc sql noprint;
select namestrip
into :name1 separated by ' '
from location;
quit;
run;
data test;
set Location(keep=XXX YYY);
length Description $250.;
do i=1 to 100;
Label XXX="XXX" ;
Label YYY="YYY";
Description=" ";
run;
data GGG.&name1.;
set test2;
if &name1.=namestrip then output;
run;
You want a program that looks like:
data loc1 (where=(namestrip='LOC1') loc2 (where=(namestrip='LOC2')) ....
set have;
run;
This program does that:
Notes:
Regards,
Mark
data have;
input namestrip $4. XXX YYY;
datalines;
loc1 1 1
loc1 1 1
loc2 3 4
loc2 7 7
loc3 3 4
loc3 7 7
run;
proc sql noprint;
select distinct
cats(namestrip
, '(where=(namestrip='
,quote(trim(namestrip))
,'))'
)
into :dslist separated by ' '
from have;
quit;
%put &=dslist;
data &dslist ;
set have;
run;
You need to put &name1. into double quotes, so it will be recognized by the data step compiler as a string literal and not a variable name.
Please stay with your original problem. Once that is solved, you will either find a solution for similar problems yourself, or we can then deal with the new question.
Have you already tried my suggestion?
I have tried your suggestion. It comes near a solution but I get no observations out.
Aren't you getting an error message from this:
set test2;
There is no data set named test2.
I tried to make it simple-Imean to set test.....
I read 300 observation in but no out.
You want a program that looks like:
data loc1 (where=(namestrip='LOC1') loc2 (where=(namestrip='LOC2')) ....
set have;
run;
This program does that:
Notes:
Regards,
Mark
data have;
input namestrip $4. XXX YYY;
datalines;
loc1 1 1
loc1 1 1
loc2 3 4
loc2 7 7
loc3 3 4
loc3 7 7
run;
proc sql noprint;
select distinct
cats(namestrip
, '(where=(namestrip='
,quote(trim(namestrip))
,'))'
)
into :dslist separated by ' '
from have;
quit;
%put &=dslist;
data &dslist ;
set have;
run;
This is a really nice solution and it works perfectlly.Thanks a lot.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.