BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
NazaninSAS
Quartz | Level 8

Hi,

 

I would like to add blank columns to an existing Dataset.

 

What do you suggest?

 

Thanks,

 

Nazanin

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

 

data want;

set sashelp.class;

char_blank=' ';

num_blank=.;

run;

 

View solution in original post

11 REPLIES 11
novinosrin
Tourmaline | Level 20

 

data want;

set sashelp.class;

char_blank=' ';

num_blank=.;

run;

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

ghosh
Barite | Level 11

 

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;

ballardw
Super User

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).

NazaninSAS
Quartz | Level 8

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

novinosrin
Tourmaline | Level 20

Revised:

 

data SelfID3WNewCoulm;

set work.SelfID3;

length f1 f2 f3 $3;

 

call missing(of f: );

number=.;

run;

novinosrin
Tourmaline | Level 20

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

 

 

NazaninSAS
Quartz | Level 8

I also tried call missing.

it works perfectly.

 

Thanks,

 

Nazanin

NazaninSAS
Quartz | Level 8

this is my new code:

data SelfID3WNewCoulm;

set work.SelfID3;

length f1 f2 f3 $4;

f1='';

f2='';

f3='';

number=.;

run;

kiranv_
Rhodochrosite | Level 12

one more way

proc sql;
Alter table have add column1 char (5), column2 num;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 32118 views
  • 4 likes
  • 6 in conversation