Hi,
I would like to add blank columns to an existing Dataset.
What do you suggest?
Thanks,
Nazanin
data want;
set sashelp.class;
char_blank=' ';
num_blank=.;
run;
Providing some information would be a start. Do you want numeric columns, character columns, lengths, labels, do you want a list with a prefix? Show an example. Can be a simple as:
data want; set have; array want{10} $100; run;
For 10 character 100 length variables. Provide some information for an accurate answer.
Here is one way. For example if you want to add two blank variables to the dataset have:
data have;
input one two three;
cards;
1 2 3
1 2 3
1 2 3
;
data want;
set have;
length four five 3;
call missing(four, five);
run;
1) You cannot add columns to an existing data set. You may create a new version of the data with the same name and different columns but adding to an "existing" is not going to happen.
2) Describe exactly what kind of columns as SAS has two data types, numeric and character. And once created they do not change.
Character variables have a property of "length" that limits how many characters. Some ways of creating a variable may only have a length of 1 character, which means if later that you want have it hold anything longer than one character you can't. Numeric fields also have a length but unless you go out of your way to make it smaller it will hold the largest/smallest values that SAS will use.
3) Adding the columns before use is likely not very useful unless you are going to manually type in values. Otherwise add the column when needed. If you combine a data set without a specific column with one that has that column the resulting combination will have that variable with blank/missing values (unless you do something during the combination to add values).
Thanks,
I used this code:
data SelfID3WNewCoulm;
set work.SelfID3;
F1=' ';
F2=' ';
F3=' ';
number=.;
run;
but how can I specify that F1, F2, and F2 to have 3-character length?
Thanks,
Nazanin
Revised:
data SelfID3WNewCoulm;
set work.SelfID3;
length f1 f2 f3 $3;
call missing(of f: );
number=.;
run;
call missing(of f: );
f: is a variable list i.e series of f variables in sequence like f1-fn
Call missing assigns missing or in other words blank values to the variable list f:
The length statement assigns the length and also helps compiler determine that f1-f3 are of type character
I hope this helps
I also tried call missing.
it works perfectly.
Thanks,
Nazanin
this is my new code:
data SelfID3WNewCoulm;
set work.SelfID3;
length f1 f2 f3 $4;
f1='';
f2='';
f3='';
number=.;
run;
great
one more way
proc sql;
Alter table have add column1 char (5), column2 num;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.