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

Hi guys!

I believe this question is already answered somewhere but I have spent last 2 hours finding elegant solution for this problem.

Imagine data set with for example 200 individuals and every individual has 40000 variables (genotypes).

IDVar_1Var_2Var_3Var_...
Var_40000
1AAB...C
2ACA...A
3BAA...B
..................
200BBC...B

I want to keep all individuals but would like to randomly select 1000 variables (genotypes).

Ok, I can do proc transpose, then randomly select and transpose back, but sometimes I have 1000000 variables and transposing is really lost of time.

Selection of variables by list would be awesome, as well direct selection based on some random function.

I believe first way is more likable and I would be very happy if someone could give a hand with this one!

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19


proc contents data=sashelp.heart noprint out=names(keep=name);
   run;
proc surveyselect sampsize=3 data=names out=sample;
   run;
%let keepvars=;
proc sql noprint;
  
select name into :keepvars separated by ' ' from sample;
   quit;
  
run;
%put NOTE: &=keepvars;
   run;
NOTE: KEEPVARS=AgeCHDdiag Sex Smoking

View solution in original post

4 REPLIES 4
data_null__
Jade | Level 19


proc contents data=sashelp.heart noprint out=names(keep=name);
   run;
proc surveyselect sampsize=3 data=names out=sample;
   run;
%let keepvars=;
proc sql noprint;
  
select name into :keepvars separated by ' ' from sample;
   quit;
  
run;
%put NOTE: &=keepvars;
   run;
NOTE: KEEPVARS=AgeCHDdiag Sex Smoking
MajaFerencakovic
Fluorite | Level 6

OK, that works but can you give me a hint about last step which would be having heart data only with this three variables?

Thanks!

MajaFerencakovic
Fluorite | Level 6

sorry! I got it! I just copy paste note to data step!

Sunday afternoon...

Thanks!

data_null__
Jade | Level 19

data randomvars;

  set sashelp.heart(keep=&keepvars);

  run;

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1665 views
  • 0 likes
  • 2 in conversation