BookmarkSubscribeRSS Feed
NonSleeper
Quartz | Level 8

The title sounds vague, but here the data looks like:

data temp;

input ID NumberOfMembers Mem1Var1 Mem1Var2 Mem2Var1 Mem2Var2 Mem3Var1 Mem3Var2;

datalines;

ID01     1     1     0     .     .     .     .

ID02     2     1     .     0     1     .     .

ID03     3     0    1     1     0     0     0

;

ID represents a type of group variable, say, families. Variables from Mem1Var1 to Mem3Var2 are characteristics measured for individual members in each group. Missing values are assigned if there are not enough members of a group to fill in these characteristics. E.g., group ID01 consists of only 1 member, thus values for Mem2Var1, Mem2Var2, Mem3Var1 and Mem3Var2 are all 0s. Let's call these "mechanical missings".

There are other missing values due to data collection etc., such as Mem1Var2 of ID02. Let's call these "other missings".

Now how can I assign the "mechanical missings" with a specific value, let's say 9? So the expected data looks like:

ID01     1     1     0     9     9     9     9

ID02     2     1     1     0     1     9     9

ID03     3     .     1     1     0     0     0

If it matters, the reason for doing so is to distinguish this type of missings. They are not really "missing" as a consequence of, for example, an error in data collection or entry leading to the incompleteness of data. Instead, they don't have values because there are no observations for those values to be measured. I think this distinguishing is useful is some cases. For example, if you transpose the data to the long form by variable 2, it looks like this for ID02:

ID         Member          Var2          NumberOfMembers

ID02     1                         .                    2

ID02     2                         1                    2

ID02     3                         .                    2

So assigning specific values will distinguish difference of missing values in Var2 and the description of data will be more accurate.

Actually, as I'm typing this, I think we can assign mechanical missings based on long form data: IF NumberOfMembers < Member THEN Var2 = 9;

Not sure what to do with wide form though.

3 REPLIES 3
Tom
Super User Tom
Super User

In addition to normal missing value (represented by a period) SAS also supports 27 special missing values (represented by period and a letter or underscore).

So use one of those to indicate the difference.

Since you have a count variable you could do it after the fact.

data temp ;

  input ID NumberOfMembers Mem1Var1 Mem1Var2 Mem2Var1 Mem2Var2 Mem3Var1 Mem3Var2;

datalines;

ID01     1     1     0     .     .     .     .

ID02     2     1     .     0     1     .     .

ID03     3     0    1     1     0     0     0

;

data want;

  set temp;

  array matrix (3,2) mem: ;

  do i=NumberOfMembers+1 to 3;

    do j=1 to 2;

      matrix(i,j)=.N;

    end;

  end;

run;

Ksharp
Super User

But the output doesn't look like what you mean .

Code: Program

data temp ;
  input ID $ NumberOfMembers Mem1Var1 Mem1Var2 Mem2Var1 Mem2Var2 Mem3Var1 Mem3Var2;
datalines;
ID01 1 1 0 . . . .
ID02 2 1 . 0 1 . .
ID03 3 0 1 1 0 0 0
;
run;
proc stdize data=temp out=want reponly missing=9;run;

ballardw
Super User

To go along with Tom's answer:

Along with the custom missing value .A and such you can ( fairly highly recommended from my point of view) also assign  custom formats to describe the specific from of missing.

The following stub program reads in a question with 5 valid response categories and a missing (could be skip pattern somewhat similar to original question), assigns special missing to categories that will generally be ignored for MOST analysis, a format to display the meaning of the special missings, and an example with proc freq of analysis with and without missing values included.

proc format library=work;
invalue Q1Missing
7=.D
9=.R
1,2,3=_same_
other= .
;
value q1missing
.D ="Don't Know"
.R ="Refused"
1  ="Yes"
2  ="No"
3  ="Not sure"
.  = "Not Answered"
;
run;

data example;
   input x q1missing.;
   format x q1missing.;
datalines;
1
2
3
7
9
.
;
run;

Proc freq data=example;
   tables x / missing;
   tables x;
run;

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 connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1313 views
  • 3 likes
  • 4 in conversation