04-05-2018 06:05 AM
In what sense? I.e. do you mean in an sql select, a keep statement, in an array? In datastep you can use the : to indicate all with prefix of and numeric suffix, e.g.:
Assuming all the variables are numeric, have the prefix of aesaf, and then have a number after, like: aesaf1, aesaf2 etc.
You can also use ranges:
To indicate all variables which logically appear between aesaf1 and aesaf10.
Context is everything in questions, follow the guidance, post test data in the form of a datastep, show what you want out at the end etc. Its hard to suggest anything with no information to go on.
04-05-2018 06:18 AM - edited 04-05-2018 06:22 AM
This does not tell me anything. Please review the guidance for posting a new question - post test data in the form of a datastep, what the output should look like. What you have written, what logs etc. The term select is vague. Let me explain:
I have a dataset which looks like:
data have; infile datalines; input aesaf1 aesaf2 aesaf3; datalines; 1 2 3 ; run;
I need to sum these variables into a new variable called result. My output should look like:
aesaf1 aesaf2 aesaf3 result
1 2 3 6
Here is code which does what you ask;
data want; set have; result=sum(of aesaf:); run;
For example, if you want to keep only those variables mentioned then:
data want (keep=asaf1--esaf1); set have; run;
You could transpose the dataset (assuming that the variables are the same) - this would be ideal as working with normalised (goes down rather than across) is far far easier and avoids problems like this that your facing.
04-05-2018 06:08 AM
data _NULL_; set have; call execute('data want; set have; keep'); do while (varname ne "varname"); call vnext(varname); suffix=substr(varname,length(varname)-3); if suffix="SAF1" then do; call execute(varname); end; end; call execute('; run;'); stop; run;
04-05-2018 06:33 AM
Having the dynamic part of the variable names in front instead of at the end is of course suboptimal, as it precludes the use of the : wildcard that SAS provides.
You will be forced to read variable names from dictionary.columns with a contains condition or similar, and put them into a macro variable with the into: clause:
proc sql noprint; select name into :varlist separated by " " from dictionary.columns where libname = 'LIBRARY' and memname = 'DATASET' and name contains 'SAF1'; quit; proc print data=library.dataset; var &varlist; run;
04-05-2018 06:43 AM
Thanks, that is right decision , but data in work and in sas help only present datas from data
I have no clue what you mean.
04-05-2018 06:46 AM
04-05-2018 06:54 AM
04-05-2018 10:56 AM
SAS doesn't work well with suffixes unfortunately.
If you have any control over the naming structure use a prefix method instead and then you can shortcut list them.
PROC SQL does not support variables lists at all though.
How select all variables which have same end,
ex. aeSAF1 beSAF1 ceSAF1 i need to select all variables ending with SAF1