I have several data sets and want to merge them.
data all7;
length company $12.;
set demo_1 demo_2 demo_3 demo_4 demo_5 demo_6 demo_7;
run;
The company is the last variable in all the 7 data sets to be merged, but it has different lengths in them.
If I use length statement to set them to the same length, the variable becomes the first one in the merged data set.
One way to work around is to set the length in all the 7 data sets first before merging. I wonder if there is a way during merge.
thanks.
you are right. The order of the variables only matters in final report.
I care it only because I have been used to the format, "visual effect" to my self.
as for the "merge" term, yes, this is a set operation (concatenation, like union in proc sql), not the speficially used merge term, which is like proc sql join. Thank you for the clarification.
Hello @fengyuwuzu,
I think, @LinusH mentioned the solution already: set a dataset twice.
data all7;
if 0 then set demo_1(drop=company); /* creates the PDV without COMPANY */
length company $12;
set demo_1 demo_2 demo_3 demo_4 demo_5 demo_6 demo_7;
run;
The above code assumes that all 7 datasets have the same variables. Otherwise, you could include more datasets into the first SET statement (which is never executed due to the IF condition).
Edit: This was also inspired by this recent post from @data_null__, who used this technique to prepare an array definition.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.