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

good day,

 

here is the problem i can't solve

i have assigned a manual name to my data set as name

now i want to do some sample check,

can i randomly draw 5 results out for each name to Verify?

and i would like to place them in the same row like this

 

name  ||  merchant_strip1 ||  merchant_strip2 || merchant_strip3 || merchant_strip4 ||merchant_strip5

 

 

here is my raw data set

 

merchant_strip Name
A A ALFA TAXI DI FIORI GENESTRERIOTICH TAXI
A A OPTICAL HONG KONG HKG OPTICAL
A A OPTICAL HONG KONG HKG OPTICAL
A A OPTICAL HONG KONG HK OPTICAL
A A OPTICAL YUEN LONG HK OPTICAL
A A OPTICAL YUEN LONG HKG OPTICAL
A AIRLINE TAXI MISSISSAUGA CAN TAXI
A AIX TAXI AIX EN PRO FR * TAXI
A ALEHOP AER VALENCIAMANISES ES ALEHOP
A B A L TOWING PTY L THORNLEIGH AUS BURBERRY
A B C DISCOUNT CARPETS CROWS NEST AU CARPET
A B SUPER MARCHE GHAZIABAD IN A B SUPER MARCH SUPERMARCHE
A BAGHLOUL TAXI GENEVE CH TAXI
A BAKERY CENTRAL A BAKERY
A BAKERY SHATIN A BAKERY
A BAKERY TAIKOO A BAKERY
A BAKERY SHATIN A BAKERY
A BAKERY C HKG HKG A1 BAKERY
A BAKERY CAFE HONGKONG HK A1 BAKERY

 

Regards,

Harry

1 ACCEPTED SOLUTION

Accepted Solutions
kelxxx
Quartz | Level 8
data have;
length group $1 j $15;
do i=1 to 300;
if i<=100 then group="A";
else if i <=200 then group="B";
else group="C";
j=cats("student",i);
output;
end;
drop i;
run;

proc sort data=have;
   by group;
run;

proc surveyselect data=have  out=Sample(keep=group j) 
                     method=srs n=(5 5 5) noprint;
      strata group;
run;

Proc transpose data=sample out=want(drop=_name_) prefix=student;
by group;
var j;
run;

i hope that its what you want

View solution in original post

6 REPLIES 6
andreas_lds
Jade | Level 19

proc surveyselect should be able to get the data, post-processing is required for the layout (maybe proc report with an across-variable).

kelxxx
Quartz | Level 8

Hi,

I didn’t quite understand your questions,
can you explain more details
with a copy of the output table please

Thanks.

harrylui
Obsidian | Level 7
or how to do sample checking for each group

for example ,i got 3 groups and each group has 100 students.
and i want to draw 5 out of 100 in each group
group A student1 student33 student36 student12 student97
group B student15 student67 student56 student77 student19
group C student19 student7 student123 student98 student61

so that i can check are these students really belong to group A/B/C because the dataset i have for now may got error
ballardw
Super User

The SELECTION part is Proc survey select. Your "grouping" variable would be a strata and you would need to sort the data set by that variable first.

 

Proc surveyselect data=have out=selected sampsize=5;

   Strata groupvariablename;

run;

 

would select 5 records for each strata. Caution: what do you want if there are not at least 5 records for each and every group? The procedure has an option to select all available SELECTALL to get all of the values if there are fewer in the group than you specified in the SAMPSIZE option.

A worked example you should be able to run:

proc sort data=sashelp.class out=work.class;
   by sex;
run;

proc surveyselect data=work.class out=work.select
    sampsize=5;
   strata sex;
run;

Then Transpose the resulting data set to get the across if really needed but the results will be grouped by the strata and since it seems like you are going to manually check something else for "accuracy" then the transpose may not be needed.

 

 

harrylui
Obsidian | Level 7

thanks all for help

kelxxx
Quartz | Level 8
data have;
length group $1 j $15;
do i=1 to 300;
if i<=100 then group="A";
else if i <=200 then group="B";
else group="C";
j=cats("student",i);
output;
end;
drop i;
run;

proc sort data=have;
   by group;
run;

proc surveyselect data=have  out=Sample(keep=group j) 
                     method=srs n=(5 5 5) noprint;
      strata group;
run;

Proc transpose data=sample out=want(drop=_name_) prefix=student;
by group;
var j;
run;

i hope that its what you want

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 6 replies
  • 641 views
  • 1 like
  • 4 in conversation