BookmarkSubscribeRSS Feed
Augusto
Obsidian | Level 7

Hi,

How to count observations using data set? I explain.

In my table "have", there are 15 observation with duplicated values (by transaction and product)

I need to get a sample (only 3 observation) per product.

How to do that?

5 REPLIES 5
Scott_Mitchell
Quartz | Level 8

Please provide a sample of the data you are working with and an example of the desired output.

Augusto
Obsidian | Level 7

Hi Scott, thanks..

in my table i have

id  financed product

1   123,67   car

1   145,90   car

1  1214,00  bike

1  1234,00  car

1  1534,00  bike

1  1094,00  car

1  1834,00  bike

1  9834,00  bike

1  1954,00  car

1  9886,00  bike

want

1   123,67   car

1   145,90   car

1  1234,00  car

1  1214,00  bike

1  1534,00  bike

1  1834,00  bike


so i need only 3 observation per product

Scott_Mitchell
Quartz | Level 8

Hi Augusto,

How about PROC SURVEYSELECT?

DATA HAVE;

INFILE DATALINES DLM=',';

INPUT ID FINANCED PRODUCT $;

DATALINES;

1,123.67,CAR

1,145.90,CAR

1,1214.00,BIKE

1,1234.00,CAR

1,1534.00,BIKE

1,1094.00,CAR

1,1834.00,BIKE

1,9834.00,BIKE

1,1954.00,CAR

1,9886.00,BIKE

;

RUN;

PROC SORT DATA=HAVE;

BY PRODUCT;

RUN;

PROC SURVEYSELECT DATA=HAVE SAMPSIZE=3 OUT=WANT SEED=0;

STRATA PRODUCT;

RUN;

yaswanthj
Fluorite | Level 6

Hi..

You can simply do using datastep.. as below..

DATA HAVE;

INFILE DATALINES DLM=',';

INPUT ID FINANCED PRODUCT $;

DATALINES;

1,123.67,CAR

1,145.90,CAR

1,1214.00,BIKE

1,1234.00,CAR

1,1534.00,BIKE

1,1094.00,CAR

1,1834.00,BIKE

1,9834.00,BIKE

1,1954.00,CAR

1,9886.00,BIKE

;

RUN;

PROC SORT DATA=HAVE;

BY PRODUCT;

RUN;

data want;

set have;

by product;

if first.product then n = 0;

n+1;

if n in (1, 2, 3) then output;

drop n;

run;

any questions ? ..

Thanks & Regards,

yaswanth J.

yaswanthj
Fluorite | Level 6

If you don`t want to mention the numbers like (1,2,3) you can write the code as follow,

data want;

set have;

by product;

if first.product then n = 0;

n+1;

if n < 4 then output;

drop n;

run;

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1486 views
  • 3 likes
  • 3 in conversation