- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I would like to add blank columns to an existing Dataset.
What do you suggest?
Thanks,
Nazanin
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data want;
set sashelp.class;
char_blank=' ';
num_blank=.;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Revised:
data SelfID3WNewCoulm;
set work.SelfID3;
length f1 f2 f3 $3;
call missing(of f: );
number=.;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I also tried call missing.
it works perfectly.
Thanks,
Nazanin
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
this is my new code:
data SelfID3WNewCoulm;
set work.SelfID3;
length f1 f2 f3 $4;
f1='';
f2='';
f3='';
number=.;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
great
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
one more way
proc sql;
Alter table have add column1 char (5), column2 num;