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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.