SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

"Randomizer" for variables :)

Accepted Solution Solved
Reply
Contributor
Posts: 40
Accepted Solution

"Randomizer" for variables :)

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!


Accepted Solutions
Solution
‎12-07-2014 08:59 AM
Respected Advisor
Posts: 3,777

Re: "Randomizer" for variables :)



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


All Replies
Solution
‎12-07-2014 08:59 AM
Respected Advisor
Posts: 3,777

Re: "Randomizer" for variables :)



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
Contributor
Posts: 40

Re: "Randomizer" for variables :)

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!

Contributor
Posts: 40

Re: "Randomizer" for variables :)

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

Sunday afternoon...

Thanks!

Respected Advisor
Posts: 3,777

Re: "Randomizer" for variables :)

data randomvars;

  set sashelp.heart(keep=&keepvars);

  run;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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