BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Linlin
Lapis Lazuli | Level 10

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

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

View solution in original post

10 REPLIES 10
Tom
Super User Tom
Super User

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_) (=);

Linlin
Lapis Lazuli | Level 10

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

art297
Opal | Level 21

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

art297
Opal | Level 21

I would think that nm2 is both a numeric variable and is missing at the time the function is applied.

data_null__
Jade | Level 19

nm2=nmiss(of _numeric_);

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. 

Linlin
Lapis Lazuli | Level 10

Thank you Art and DN! 

Linlin

Howles
Quartz | Level 8

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

art297
Opal | Level 21

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;

Ksharp
Super User

It is very intesting.

Actually cats2 = cats(of _numeric_) ; is the same with

cats2 = input(cats(of v1-v5) ,best.);

Ksharp

Linlin
Lapis Lazuli | Level 10

Hi Mr. Schreier,

I just finished reading your paper. It is a very good paper.  Thanks - Linlin

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 10 replies
  • 2073 views
  • 6 likes
  • 6 in conversation