## Creating data with missing values

Solved
Occasional Contributor
Posts: 8

# Creating data with missing values

Hello,

This is my output data file:

How can I make those marked (in the picture) values = missing?

Here's my code:

```%let skirstinys = rannor; /* distribution */
%let imciu_sk = 2; /* data count */
%let imties_dydis = 10; /* data size */
%let LAG = 4;
%let cmax = 0.9;
%let cmin = 0.1;
%let cvalue = (&cmax.-&cmin.)/(&LAG.-1);

data duomenys;
/* const array */
array c{&LAG.};
do q = 1 to dim(c);
c(q)=&cmax.-(&cvalue.*(q-1));
end;

/* X1,X2.. array*/
array X{&LAG.};
do n = 1 to dim(X);
X(n) = &skirstinys.(1);
end;

/* data */
do imtis = 1 to &imciu_sk.;
do i = 1 to &imties_dydis.;
e1=&skirstinys.(1);
XX=e1;
do j=1 to dim(c);
XX=XX+c(j)*X(j);
end;
output;
do f = (&LAG.-1) to 1 by -1;
X(f+1)=X(f);
end;
X1=e1;
end;
end;
proc print;
run;```

I'm making a research about observations dependence of nonstationary process using nonparametric statistics. I need to generate time series with various LAG selections.

XX is generated using MA(q) process.

Accepted Solutions
Solution
‎05-19-2016 01:03 PM
Posts: 1,259

## Re: Creating data with missing values

So, you want to delete all observations which had i=1, 2 or 3 in your original DUOMENYS dataset? Then you don't need an additional counter CTR, because you can simply use variable i itself:

``if i>3 then output;``

This would suppress the first three observations for every value of IMTIS (if that's what you meant by "every imtis=imtis").

The new dataset DUOMENYS2 I created using the FIRSTOBS=4 dataset option has 20-3=17 observations. That is, the former first three observations are really gone (not from DUOMENYS, of course). They are not just "not printed."

All Replies
Posts: 1,259

## Re: Creating data with missing values

[ Edited ]

You could add the following line after the assignment statement "X(n) = ..." in the loop "do n = 1 ...":

``  if _n_<n then X(n)=.;``

Please note that this would cause missing values of variable XX in the first three observations as well (and, as a consequence, undesirable notes "Missing values were generated ..." in the log). So, you may want to modify the definition of XX correspondingly.

Edit: The conditional assignment proposed above can be simplified to:

``  if n>1 then X(n)=.;``

Reason: The data step iterates only once, hence _n_=1. The assignment statements in the loop "do n = 1 ..." affect only the first observation of the output dataset directly, whereas the values of X1-X4 in the subsequent observations are set in the loop "do i = 1 ...".

Occasional Contributor
Posts: 8

## Re: Creating data with missing values

[ Edited ]

How could I delete those first 3 lines in every i=1,2,3 and have fresh data set without them?

Posts: 1,259

## Re: Creating data with missing values

If you want to suppress the output of the first three lines (observations), you can replace the OUTPUT statement by the following three lines of code:

``````   ctr+1;
if ctr>3 then output;
drop ctr;``````

This creates a counter variable CTR, which is incremented by 1 every time the OUTPUT statement would execute in your original code. The IF condition prevents the execution of the OUTPUT statement for the first three times.

If you want to create a new ("fresh") dataset without the first three observations of DUOMENYS, you can use the FIRSTOBS= dataset option:

``````data duomenys2;
set duomenys(firstobs=4);
run;``````
Occasional Contributor
Posts: 8

## Re: Creating data with missing values

I need to suppress every imtis=imtis, or every i=1,2,3. The firstobs doesn't remove those lines from the file, it just print less than there is.
Solution
‎05-19-2016 01:03 PM
Posts: 1,259

## Re: Creating data with missing values

So, you want to delete all observations which had i=1, 2 or 3 in your original DUOMENYS dataset? Then you don't need an additional counter CTR, because you can simply use variable i itself:

``if i>3 then output;``

This would suppress the first three observations for every value of IMTIS (if that's what you meant by "every imtis=imtis").

The new dataset DUOMENYS2 I created using the FIRSTOBS=4 dataset option has 20-3=17 observations. That is, the former first three observations are really gone (not from DUOMENYS, of course). They are not just "not printed."

🔒 This topic is solved and locked.