Did you try the code?
Which code ? this one
data want;
set dsnaC: INDSNAME=SOURCE;
DNAME=SOURCE;
run;
No I didn't
Because
I don't understand INDSNAME=SOURCE and DNAME=SOURCE;
How could I use ?
The colon after then prefix dsnac tells SAS to append all datasets that start with the prefix.
The indsname option tells sas to capture the name of the dataset where the observation comes from. This variable isn't stored automatically so the next line DName=source tells SAS to explicitly keep the name.
This way you know which observations come from which data set. These statements are optional, my initial code with only the colon would exclude these options.
Actually the data sets which I want to combine are not in series they are like
DsnAC16 DsnAC17......DsnAC125
then
DsnAC26 DsnAC27.....DsnAC225
...
DsnAC56 DsnAC57.....DsnAC525
So how could I used colon ? for this
And I no need to know which observation is coming from which data set
I just want to combine all data set thats it
I have to use two do loops to combine these set of data sets but I am unable to write this code
Unless you have other data sets such as DsnAC05 that you don't want to include then the colon operator will work.
But if you don't want to try it, no one can force you. Good luck.
Oh sorry
Now I try your initial code and its works fine thank you very much reeza you solved my problem thank again
But there is only one problem about arrangement of combining data sets
I am getting following arrangement of combine data set
WORK.DSNAC110.
WORK.DSNAC111.
WORK.DSNAC112.
WORK.DSNAC113.
WORK.DSNAC114.
WORK.DSNAC115.
WORK.DSNAC116.
WORK.DSNAC117.
WORK.DSNAC118.
WORK.DSNAC119.
WORK.DSNAC120.
WORK.DSNAC121.
WORK.DSNAC122.
WORK.DSNAC13.
WORK.DSNAC14.
WORK.DSNAC15.
WORK.DSNAC16.
WORK.DSNAC17.
WORK.DSNAC18.
WORK.DSNAC19.
WORK.DSNAC210.
WORK.DSNAC211.
WORK.DSNAC212.
WORK.DSNAC213.
WORK.DSNAC214.
WORK.DSNAC215.
WORK.DSNAC216.
WORK.DSNAC217.
WORK.DSNAC218.
WORK.DSNAC219.
WORK.DSNAC220.
WORK.DSNAC221.
WORK.DSNAC222.
WORK.DSNAC23.
WORK.DSNAC24.
WORK.DSNAC25.
WORK.DSNAC26.
WORK.DSNAC27.
WORK.DSNAC28.
WORK.DSNAC29.
But I need following arrangements pls guide I would be grateful to you
WORK.DSNAC13.
WORK.DSNAC14.
WORK.DSNAC15.
WORK.DSNAC16.
WORK.DSNAC17.
WORK.DSNAC18.
WORK.DSNAC19.
WORK.DSNAC110.
WORK.DSNAC111.
WORK.DSNAC112.
WORK.DSNAC113.
WORK.DSNAC114.
WORK.DSNAC115.
WORK.DSNAC116.
WORK.DSNAC117.
WORK.DSNAC118.
WORK.DSNAC119.
WORK.DSNAC120.
WORK.DSNAC121.
WORK.DSNAC122.
WORK.DSNAC23.
WORK.DSNAC24.
WORK.DSNAC25.
WORK.DSNAC26.
WORK.DSNAC27.
WORK.DSNAC28.
WORK.DSNAC29.
WORK.DSNAC210.
WORK.DSNAC211.
WORK.DSNAC212.
WORK.DSNAC213.
WORK.DSNAC214.
WORK.DSNAC215.
WORK.DSNAC216.
WORK.DSNAC217.
WORK.DSNAC218.
WORK.DSNAC219.
WORK.DSNAC220.
WORK.DSNAC221.
WORK.DSNAC222.
One way to generate a list of data set names without a macro is to generate the list into a macro VARIABLE instead. This assumes that the list is short enough to fit into a macro variable.
%let a=5;
%let b=20;
data _null_;
length allmergeac $32767 ;
do k= 1 to &a;
do h= 1+&a to &b+&a;
allmergeac=catx(' ',allmergeac,cats('dsnAC',k,h));
end;
end;
call symputx('allmergeac',allmergeac);
run;
data combineAC;
set &allmergeAC ;
run;
But why do you care what order the datasets are combined? Don't the datasets already have variables that would let you combine them properly? For example it looks like you are building the dataset name from two variables K and H. If those variables are on the datasets then just add a BY statement.
data combineAC;
set dsnAC: ;
by k h ;
run;
If not then you will want to generate the names in a way that WILL sort naturally and that also will allow you to parse out the values of these two key variables from the name. One way is to include the leading zeros so that they will sort. Obviously you will also need to do this in the program that creates the datasets.
%macro allmergeAC (a,b);
%do k= 1 %to &a;
%do h= %eval(1+&a) %to %eval(&b+&a);
dsnAC%sysfunc(putn(&k,Z2))%sysfunc(putn(&h,Z2))
%end;
%end;
%mend;
data combineAC;
set %allmergeAC(5,20) ;
run;
Thank Tom I run this program and its work fine
Regards
A simple way is sorting these table name firstly ,after that SET them all.
data WORK.DSNAC120
WORK.DSNAC121
WORK.DSNAC122
WORK.DSNAC23
WORK.DSNAC24
WORK.DSNAC25
;
set sashelp.class;
run;
proc sql;
select memname into : list separated by ' '
from dictionary.members
where libname='WORK' and memtype='DATA' and memname like 'DSNAC%'
order by memname;
quit;
data want;
set &list;
run;
Notes (17)
53
54 data WORK.DSNAC120
55 WORK.DSNAC121
56 WORK.DSNAC122
57 WORK.DSNAC23
58 WORK.DSNAC24
59 WORK.DSNAC25
60 ;
61 set sashelp.class;
62 run;
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.DSNAC120 has 19 observations and 5 variables.
NOTE: The data set WORK.DSNAC121 has 19 observations and 5 variables.
NOTE: The data set WORK.DSNAC122 has 19 observations and 5 variables.
NOTE: The data set WORK.DSNAC23 has 19 observations and 5 variables.
NOTE: The data set WORK.DSNAC24 has 19 observations and 5 variables.
NOTE: The data set WORK.DSNAC25 has 19 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.01 seconds
63 proc sql;
64 select memname into : list separated by ' '
65 from dictionary.members
66 where libname='WORK' and memtype='DATA' and memname like 'DSNAC%'
67 order by memname;
68 quit;
NOTE: PROCEDURE SQL used (Total process time):
real time 0.60 seconds
cpu time 0.26 seconds
69 data want;
70 set &list;
71 run;
NOTE: There were 19 observations read from the data set WORK.DSNAC120.
NOTE: There were 19 observations read from the data set WORK.DSNAC121.
NOTE: There were 19 observations read from the data set WORK.DSNAC122.
NOTE: There were 19 observations read from the data set WORK.DSNAC23.
NOTE: There were 19 observations read from the data set WORK.DSNAC24.
NOTE: There were 19 observations read from the data set WORK.DSNAC25.
NOTE: The data set WORK.WANT has 114 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.32 seconds
cpu time 0.26 seconds
72
73 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
83
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.