BookmarkSubscribeRSS Feed
Anv_SAS
Calcite | Level 5

Hi all,

 

I am trying to create a zero dataset with DATASTEP, which contains only attrib information or we can assign/modify attributes of variables.

 

Below is the code:

 

data x;
attrib
x label="X" length=$25.;
stop;
run;

 

But I'm getting below warning

 

15274 data x;
15275 attrib
15276 x label="X" length=$25.;
15277 stop;
15278 run;

NOTE: Variable x is uninitialized.
NOTE: The data set WORK.X has 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
cpu time 0.00 seconds

 

Please anyone can help me in fixing this.

 

Regards,

Anv_SAS

7 REPLIES 7
Anv_SAS
Calcite | Level 5
Thank you KurtBremser,

We cannot assign value to x. Only can using attrib statement, is this possible using datastep. Do we have any other way to this.
FreelanceReinh
Jade | Level 19

Hi @Anv_SAS,

 

Put the assignment statement (or CALL MISSING, etc.) after the STOP statement. Then it will not be executed, i.e., you really don't assign a value. Nevertheless, the note in the log will no longer appear because the compiler sees an assignment.

 

Edit: Alternatively you can use a RETAIN statement with an initial value if you prefer a declarative statement.

Tom
Super User Tom
Super User

Adding the variables to an ARRAY will prevent the message.  But you need a separate array for the numeric and character variables.

You can also use the CALL MISSING() function.

110   data x;
111     attrib x label="X" length=$25;
112     array _ _character_;
113     stop;
114   run;

NOTE: The data set WORK.X has 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.03 seconds


115
116   data x;
117     attrib x label="X" length=$25;
118     stop;
119     call missing(of _all_);
120   run;

NOTE: The data set WORK.X has 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.01 seconds

PS  There is no need to include a decimal point when specifying a length.  Lengths can only be integers. 

Reeza
Super User
Why the requirement for the attrib statement? You can definitely creating empty data sets without any values, not sure the attributes statement is the way to do that though.
Ksharp
Super User

Then give X a initial value(missing value).


data x;
attrib x label="X" length=$25.;
x=' ';
stop;
run;

 

OR Try PROC SQL



proc sql;
create table x (
x char(25) label='X'
);
quit;

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 1146 views
  • 3 likes
  • 6 in conversation