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

I have a deck of cards using the following data step.

How can I mix-up the cards in the dataset so that I can play 21?

data cards(keep=card suit c2);
do c1= 1 to 4;
	if c1=1 then suit='C';
	else if c1=2 then suit='D';
	else if c1=3 then suit='H';
	else if c1=4 then suit='S';
	do c2= 1 to 13;
		card=c2||suit;
		output;
	end;
end;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Keep it simple:

 

data cards;
length card $3;
do suit = "C", "D", "H", "S";
	do c2= 1 to 13;
		card=cats(c2,suit);
		output;
		end;
	end;
run;

proc sql;
create table shuffled as select * from cards order by rand("uniform");
quit;
PG

View solution in original post

3 REPLIES 3
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

thank you @Reeza 

PGStats
Opal | Level 21

Keep it simple:

 

data cards;
length card $3;
do suit = "C", "D", "H", "S";
	do c2= 1 to 13;
		card=cats(c2,suit);
		output;
		end;
	end;
run;

proc sql;
create table shuffled as select * from cards order by rand("uniform");
quit;
PG

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 972 views
  • 6 likes
  • 3 in conversation