I have meta data extracted into data set b like this
proc contents data = t out = b noprint nodetails;
run;
in data set b, I just use Name, Type, Length.
Now, I want to create data set "addi" using the data set b, then append the data set addi to data set t.
How do I do that?
I want to do this so that appending data set won't have inconsistent length or data type issue.
I think you would have to write a macro so that all variables in addi have the same type and length as in data set t.
But I'm curious, why don't you just use PROC APPEND with the FORCE option? Does that not work?
Data set t has only name, type and length as well?
It seems weird to want to want to append the contents result to the data you originally ran it on...
Anyways, assuming it makes sense.
data addi;
set b;
keep name type length;
*other things go here;
run;
proc append base=t data=addi force;
run;
The usual way to copy all the attributes does not bother with a PROC CONTENTS. Instead:
data addi;
if 0 then set t;
* additional statements to read in data to addi;
run;
Just having SET T at the start of the program will set up all the variable attributes in exactly the same way they are defined in T. There is no need to actually read in any of the data, hence IF 0 which is always false.
Good luck.
I recommend just using PROC APPEND, but assuming you only have dataset B you can use that to generate a LENGTH statement.
proc sql noprint ;
select catx(' ',name,cats(case when (type=2) then '$' else ' ' end,length))
into :varlist separated by ' '
from b
;
quit;
data addi;
length &varlist ;
.... code to populate variables .... ;
run;
It would be better to include VARNUM in the metadata so that you could create the variables in the proper order. (Note generating macro variable DUMMY to suppress SQL message when order variable not included in the SELECT list.)
proc sql noprint ;
select catx(' ',name,cats(case when (type=2) then '$' else ' ' end,length))
, varnum
into :varlist separated by ' '
, dummy
from b
order by varnum
;
quit;
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.