BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ascasfaegADGSgs
Fluorite | Level 6

Hello,


This is my output data file:

Screen Shot 2016-05-19 at 14.43.54.png

 

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.

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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

View solution in original post

5 REPLIES 5
FreelanceReinh
Jade | Level 19

Hello @ascasfaegADGSgs,

 

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

ascasfaegADGSgs
Fluorite | Level 6

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

FreelanceReinh
Jade | Level 19

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;
ascasfaegADGSgs
Fluorite | Level 6
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.
FreelanceReinh
Jade | Level 19

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

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
  • 5 replies
  • 866 views
  • 1 like
  • 2 in conversation