Hi, I have ~200 data-sets that are stored in 1 library (that I've called "mbuild"). Each dataset has 1 row of data that is the mean and percentiles for 1 variable. In each dataset, the variable information (e.g., height, weight, etc.) is only stored in the label. The datasets are numbered in sets of 54 (e.g. mbuild.ADmb_RBC1_1 -> mbuild.ADmb_RBC1_54, mbuild.ADmb_SF1_1 -> mbuild.ADmb_SF1_54... etc,). I want them all in the same dataset, and initially, used this macro ( a few times, per the changing names) to stack them: %MACRO GENSET(FILEPFX=, LOW=, HIGH=); %DO CYC=&LOW %TO &HIGH; &FILEPFX&CYC %END; %MEND GENSET; data want ; set %GENSET(FILEPFX= mbuild.ADmb_RBC1_, LOW=1, HIGH=54); run; It worked perfectly, but, the information in the label is lost, so I can't tell which row goes to which dataset (of course I could manually line them up, but I want to automate it). I updated a macro I found on this site (thanks!!) to read through the list of datasets, extract the label and create a new dataset with the data labeled: %macro getlabel (x=); %let total_vars = %sysfunc(countw(&x) ); %do i = 1 %to &total_vars; %let selected_var = %scan(&x, &i); data new_&i ; set &selected_var; comp = vlabel(Mean); run; %end; %mend; I then loop in the %genset macros, and it should give me datasets new_1 to new_200, that I can stack together for additional analyses. The macro works perfectly when I test it using datasets that I've copied into the working library: data test1; set mbuild.ADmb_SF1_1; run; data test2; set mbuild.ADmb_SF1_2; run; data test3; set mbuild.ADmb_SF1_3; run; data prac1; set mbuild.ADmb_SF1_1; run; data prac2; set mbuild.ADmb_SF1_2; run; data prac3; set mbuild.ADmb_SF1_3; run; %getlabel (x = %GENSET(FILEPFX= test, LOW=1, HIGH=3); %GENSET(FILEPFX= prac, LOW=1, HIGH=3);); All 6 datasets are created, and have the 5 variables that I want (the original 4+ the new variable "comp" with the label in it) But, If I try to call in the datasets where they currently reside (the 'mbuild' library) - I'm getting an error that makes it seem like the macro can't read the libname? : The %genset macro works perfectly on its own (and reads the libname correctly), but once its inside the %getlabel macro it crashes. I tried to update the above macro to first copy all of the datasets into the working library (below, in case useful), but I'm getting similar errors %macro movetowork (x=); %let total_vars = %sysfunc(countw(&x) ); %do i = 1 %to &total_vars; %let selected_var = %scan(&x, &i); data new_&selected_var ; set &selected_var; run; %end; %mend; Is there a way to update the macro so it reads "mbuild" as the dataset's libname? Thank you so much!
... View more