sas - _NULL_ preventing overwriting table? - Stack Overflow
What does “null” mean and why is it here
Why the hate for null?
I’m done with null.. what now?
Cause skulk around in low sec with me. Sometimes I hunt, sometimes im hunted, but I'm never bored.
More on reddit.comSo I use C# and I often see many devs use null.
What and which kind of situation do you use this variable?
I am reading c# guide on programming book and I am on Clearing memory now and I haven't encountered null yet. Should I be worried?
Here's some comments that may help. Basically, as others have indicated, _NULL_ does not create an output data set so your assumption there is incorrect.
You're also using FILE incorrectly I suspect but don't know what you're trying to do with that statement.
You also are using a DO OVER loop which is deprecated as of SAS V7 so you shouldn't use it in production code.
DATa _NULL_;*_Null_ means no output data set is created;
SET TEMP1; *input data set means temp1;
file print; *writes to a file named print, no filename statement so no idea what this means to you;
array a1 _numeric_; *creates an array of all numeric values;
do over a1; *Do over is deprecated as of 20 years ago, it works but I don't recommend using it in production code;
if a1=. then a1=0; *replaces missing with 0;
end;*ends loop;
*no put statements so nothing is written the file print;
run;
You could fix it by doing this, but I don't recommend using the same data set name. It makes it hard to debug your code later on.
/* step to overwrite WORK.TEMP1 dots with 0 */
DATa TEMP1;
SET TEMP1;
array a1 _numeric_;
do over a1;
if a1=. then a1=0;
end;
run;
Here are two different ways to replace values in an existing table
- overwriting the entire table with a new copy of itself
data name; set name; …
- modifying values in-place within existing table
data name; modify name; …
Example
1 data class;
2 set sashelp.class;
3 run;
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.CLASS has 19 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.17 seconds
cpu time 0.00 seconds
4
5 data class; /* output data set named is same as input data set */
6 set class;
7 age = age * 2;
8 run;
NOTE: There were 19 observations read from the data set WORK.CLASS.
NOTE: The data set WORK.CLASS has 19 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.03 seconds
9
10 data class; /* output data set name */
11 modify class; /* is same as modify name, values updated in place */
12 age = age / 2;
13 run; /* observations are rewritten (see log) */
NOTE: There were 19 observations read from the data set WORK.CLASS.
NOTE: The data set WORK.CLASS has been updated. There were 19 observations rewritten, 0
observations added and 0 observations deleted.
NOTE: DATA statement used (Total process time):
real time 0.05 seconds
cpu time 0.00 seconds
A third way would be to use SQL UPDATE statement with sets based on coalesce, however, that is not amenable to array processing.
Proc SQL;
update mydata set
a1 = coalesce (a1,0)
, s2 = coalesce (a2,0)
…
;