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?
Please provide a sample of the data you are working with and an example of the desired output.
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
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;
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.
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;
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.
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.
Ready to level-up your skills? Choose your own adventure.