04-04-2013 07:50 AM
I have a question concerning the selection of certain variables in a dataset:
Let's say my dataset has the variables var1, var2, ...var100. For an analysis with a certain procedure I need every fifth variable (var5, var10, var15,...).
Is there an easy way to adress these variables? I thought of building an array with dimenstion [20,5] and writing the 5th column in an array with . So I can adress them as new1-new20:
array old[20,5] var1-var100
array new 
do i=1 to 20;
Is there another, better way to do this without creating new variables?
Tanks a lot for your help.
04-04-2013 09:04 AM
I would use this technique. I use it all the time to process variables lists. Data V is my test data you will use YOUR data of course. Be sure to use OBS=0 data set option on the transpose when you replace V with your data set name.
Message was edited by: data _null_
04-04-2013 09:06 AM
maybe I missundstood your question.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
array old(*) v1-v15;
array new(*) new1-new3;
do i=1 to 3;
Obs v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 new1 new2 new3
1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 5 10 15
04-04-2013 09:28 AM
Or you can take advantage of some Metadata:
select CATS(name) into :varname separated by ' ' from dictionary.columns
SET YOURTABLE (KEEP=&VARNAME);
All of your wanted variable names will in macro variable 'varname' , ready for use.
04-04-2013 07:46 PM
If the variables are in the form var1 - var100 you could use a macro to define the keep list (or variables in an array)
%macro keepvar ;
%global keepvar ;
%do i = 5 %to 100 %by 5 ;
%let keepvar = &keepvar var(%left(i)) ;