Hi All,
Why nm2=1 in my output?
Thanks!
data check;
input v1-v5 ;
cards;
1 2 3 4 5
;
run;
data look;
set check;
nm1=nmiss(of v1-v5);
nm2=nmiss(of _numeric_);
run;
proc print;run;
Obs v1 v2 v3 v4 v5 nm1 nm2
1 1 2 3 4 5 0 1
I don't think put statements will explain it for you. Possibly the following will:
data check;
input v1-v5 ;
cards;
1 2 3 4 5
5 4 3 2 1
;
run;
data look;
set check;
v6=nmiss(of v1-v7);
v7=nmiss(of _numeric_);
run;
proc print;run;
A nice explanation of what gets added to the PDV, and when, can be found at: http://www.lexjansen.com/nesug/nesug88/sas_supervisor.pdf
See what you get if you reverse the order of the two assignment statements.
Also try putting this statement at a few places in your data step.
put (_numeric_) (=);
Thank you Tom!
this is what I got after making changes as you suggested:
data check;
input v1-v5 ;
cards;
1 2 3 4 5
;
run;
data look;
set check;
put (_numeric_) (=);
nm2=nmiss(of _numeric_);
put (_numeric_) (=);
nm1=nmiss(of v1-v5);
put (_numeric_) (=);
run;
proc print;run;
Obs v1 v2 v3 v4 v5 nm2 nm1
1 1 2 3 4 5 1 0
From log file:
301 data check;
302 input v1-v5 ;
303 cards;
NOTE: The data set WORK.CHECK has 1 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
305 ;
306 run;
307
308 data look;
309 set check;
310 put (_numeric_) (=);
311 nm2=nmiss(of _numeric_);
312 put (_numeric_) (=);
313 nm1=nmiss(of v1-v5);
314 put (_numeric_) (=);
315 run;
v1=1 v2=2 v3=3 v4=4 v5=5
v1=1 v2=2 v3=3 v4=4 v5=5 nm2=1
v1=1 v2=2 v3=3 v4=4 v5=5 nm2=1 nm1=0
NOTE: There were 1 observations read from the data set WORK.CHECK.
NOTE: The data set WORK.LOOK has 1 observations and 7 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
316 proc print;run;
NOTE: There were 1 observations read from the data set WORK.LOOK.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
I don't think put statements will explain it for you. Possibly the following will:
data check;
input v1-v5 ;
cards;
1 2 3 4 5
5 4 3 2 1
;
run;
data look;
set check;
v6=nmiss(of v1-v7);
v7=nmiss(of _numeric_);
run;
proc print;run;
A nice explanation of what gets added to the PDV, and when, can be found at: http://www.lexjansen.com/nesug/nesug88/sas_supervisor.pdf
I would think that nm2 is both a numeric variable and is missing at the time the function is applied.
NM2 is included in the list _NUMERIC_ as it is created and added to the PDV before the list for NMISS(of _NUMERIC_) is evaluated by the compiler.
Thank you Art and DN!
Linlin
Here's a variation using CATS rather than NMISS.
data check ;
input v1 - v5 ;
cards ;
1 2 3 4 5
;
data look ;
set check ;
cats1 = cats(of v1 - v5 ) ;
cats2 = cats(of _numeric_) ;
run ;
Both new variables receive the value 12345, but CATS1 is character while CATS2 is numeric. I explain in my SESUG paper
Using SAS® Variable Lists Effectively (pp. 14-15).
Howard, Thanks! I learned at least one new thing from your paper. I had never seen numeric and character used in the way you showed in your paper, i.e.:
proc print data=sashelp.class;
var name-numeric-weight;
run;
It is very intesting.
Actually cats2 = cats(of _numeric_) ; is the same with
cats2 = input(cats(of v1-v5) ,best.);
Ksharp
Hi Mr. Schreier,
I just finished reading your paper. It is a very good paper. Thanks - Linlin
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.