Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating new variables without any data

Status
Not open for further replies.

noway320

MIS
Aug 12, 2010
19
US
How can i create new variables but no data, like absolutely blank, no zero, no periods in SAS?
 
In the normal data step, the trick is to stop SAS from returning to the top of the implicit loop. Metadata attributes get defined at compilation time, so you can define variables with formats, labels and lengths without having any records.

data step:

Code:
data blank1 ;
   dummy1 ='';
   dummy2 = 999 ;
   label dummy1 = 'Dummy variable 1'
         dummy2 = 'Dummy variable 2';
   stop ;
   run;
proc print;run;

SQL:

Code:
proc sql ;
  create table blank2 
  ( 
     DUMMY1 CHAR(1) LABEL='Dummy variable 1',
     DUMMY2 NUM (8) LABEL='Dummy variable 2'
   ) ;
   quit ;
 
Well, I have already a dataset in which i wants to create multiple variables which are blank.
 
Do you want to create blank character variables or numeric variables?

From your first post, I assume you mean numeric variables. SAS uses the period to highlight the missing variable is of type numeric, so other than using a format, I don't think you can change the appearance to a blank in the dataset. However for all reporting/printing purposes, you can use the missing option and set it to blank.

Code:
options missing=' ';
data class ;
   set sashelp.class ;
   call missing(x,y,z) ;*Create missing numerics x,y,z;
   run;
proc report data=class ;
   columns _all_ ;
   define _all_ / width=10 ;
   run;

For characters, a retain is probably the most efficient way:
Code:
data class ;
   set sashelp.class ;
   retain x y z '';
   run;
proc report data=class ;
   columns _all_ ;
   define _all_ / width=10 ;
   run;
 
We can use proc SQL, like Alter table statement, because i got the answer but let me try the code of yours.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top