sas >> Extracting every nth observation from data

by wing.tham03 » Mon, 25 Apr 2005 19:41:17 GMT

Dear folks,

I have tried to extract every 50th observations from my set of data using
Proc Expand. I have realised that the procedure interpolate my missing
values. Can someone suggest how can i leave the interpolation out when
using proc expand. The following code is what i have used.

proc expand data="g:\MTS_ data\sas\abmayIT0003190912" out=test factor=
(1:50);
convert _1vol=_1vol / observed=end;
convert bestask=bestask / observed=end;
convert _2vol=_2vol / observed=end;
convert ask2=ask2 / observed=end;
convert _3vol=_3vol / observed=end;
convert ask3=ask3 / observed=end;
convert _4vol=_4vol / observed=end;
convert ask4=ask4 / observed=end;
convert _5vol=_5vol / observed=end;
convert ask5=ask5 / observed=end;
convert _6vol=_6vol / observed=end;
convert ask6=ask6 / observed=end;

run;


I have missing values in some of the columes and i want to leave them as
missing values while extracting every 50th line. Thanks in advance.

Regards
wing wah

sas >> Extracting every nth observation from data

by art297 » Tue, 26 Apr 2005 01:17:13 GMT


Wing,

I'm not familiar with the procedure but, according to the online
documentation:

"To interpolate missing values in time series without converting the
observation frequency, leave off the TO= option. For example, the
following statements interpolate any missing values in the time series in
the data set ANNUAL.

proc expand data=annual out=new from=year;
id date;
convert x y z;
convert a b c / observed=total;
run;

To interpolate missing values in variables observed at specific points in
time, omit both the FROM= and TO= options and use the ID statement to
supply time values for the observations. The observations do not need to
be periodic or form regular time series, but the data set must be sorted
by the ID variable. For example, the following statements interpolate any
missing values in the numeric variables in the data set A."

Art
-----
On Mon, 25 Apr 2005 07:41:17 -0400, Wing Wah < XXXX@XXXXX.COM >

sas >> Extracting every nth observation from data

by m.f.dixon » Tue, 26 Apr 2005 03:32:06 GMT


using

[snip]

David wrote (in part):

If you really need records 50, 100, 150, ... then you can get there
easier by using a simple DATA step and the automatic variable _N_,
which is the number of the record in the data step. (Actually, the
meaning of _N_ is more complex than that, and you should read up on
it if you plan to use it.) Try this:

data YourOutput;
set YourInput;
if mod(_n_,50) = 0;
run;



[Dixon, Mark] --------------------------


Another way to do this would be to use the point option on the dataset to
read only every 50th record - this will be quicker than reading the whole
dataset and only outputting every 50th observation if the dataset is large,
but the difference in speed is likely to be small otherwise.

data foo;
do i = 1 to nobs by 50;
set YourData point=i nobs=nobs;
output;
end;
stop; /*needed as non sequential reading of dataset with 'point' mean the
usual eof indicator is not read*/
run;

Regards,

Mark

Similar Threads

1. Fwd: how to get every m observation from one data set

2. compare every observation in the data set to the rest of them

3. how to get every m observation from one data set

hi

Here is the sample data:

data one;
        input a;
datalines;
1
2
3
4
5
6
7
8
9
10
;

Here is the data I want for every 3 obs:
1  4  7
2  5 8
3  6 9
10 0 0

I set the data to 0 if no such position.

I tried to transpose first then use array. But the code is very complicated
and can not deal with the irregular data.

Thanks in advance.

Ming

4. Appending new columns to every observation

5. proc univariate on every observation

Below is the output from proc contents data=_all_; in which there are
13 datasets.  Each dataset has several date variables, I want to run a
proc univariate to get the min/max of each date in each dataset.

so basically I want to run the following code over and over for each
record below:

proc univariate data=dataset1 ( <= change with next record);
var date1 ( <= change with next record);
output out=temp min=min max=max;
run;
Thanks,
F

Obs    count    MEMNAME       NAME       cnt

  1       1     dataset1      date1     1
  2       1     dataset1      date2     2
  3       1     dataset1      date3     3
  4       2     dataset2      date1     1
  5       2     dataset2      date2     2
  6       2     dataset2      date3     3
  7       3     dataset3      date1     1
  8       4     dataset4      date1     1
  9       4     dataset4      date2     2
 10       5     dataset5      date1     1
 11       5     dataset5      date2     2
 12       6     dataset6      date1     1
 13       7     dataset7      date1     1
 14       7     dataset7      date2     2
 15       8     dataset8      date1     1
 16       8     dataset8      date2     2
 17       9     dataset9      date1     1
 18      10     dataset10     date1     1
 19      11     dataset11     date1     1
 20      11     dataset11     date2     2
 21      12     dataset12     date1     1
 22      13     dataset13     date1     1
 23      13     dataset13     date2     2

6. How do you read every 3rd observations in a dataset

7. Bolding one observation every time it appears

Is there any way to bold one observation whenever it appears in a report?
I'm using proc report, and one of the lines needs to be bolded every time
that observation appears. The data look like this (thanks, Art Tabachneck
and Phil Crane):


id     _NAME_    AY99    r99     ay00    r00
123    Measure1  12345    2      67890    1
456    Measure1  98765    1      54321    2
123    Measure2  78901    1      67895    2
456    Measure2  66554    2      99887    1

I read it with this:

proc report data=report9802 nowd;
 column id _name_
 ('AY 1998-99' ay99 r99)
 ('AY 1999-00' ay00 r00)
 define id / group ' ';
        define measure / group noprint;
 define ay99 / 'Value' f=comma8.;
 define ay00 / 'Value' f=comma8.;
 define r99 / 'Rank';
 define r00 / 'Rank';
 break after _name_ / page;
 compute before _page_ / style= {just=l font_weight=bold};
  line 'Measure: ' _name_ $itemf.;
 endcomp;
run;

Output looks like this:
Measure: Measure1
id      AY99    r99      ay00    r00
123    12,345    2      67,890    1 *I want this line boldfaced;
456    98,765    1      54,321    2
123    78,901    1      67,895    2 *I want this line boldfaced;
456    66,554    2      99,887    1

I'd do it manually, but the report is 500 pages long.

TIA,

Pat Moore

8. how to delete every 100 th observation