hi,
I am computing a variable in a data set and want to output only this variable into the data set.
data a;
set b c;
xvar = <some calculation using fields from datasets b and c > ;
I want to append/add only this xvar into dataset a and ignore other variables in the PDV. I have many variable and keep and drop is getting tedious.
My question is how can I selectively select variables from the PDV and write to the data set a;
2. My second question is regarding aliasing. Is there sql like aliasing within the dataset code. I dont want to use proc sql.
data a;
set b alias x c alias y;
if x.fld1 <> y.fld1 then do;
<some processing>
end;
run;
regards
jana
What do you mean - "I was hoping there would be some way out"? If there is no logical way of identifying variables - such as using prefix's and then shortcuts that way, then how can the computer know what you want to keep? We need to see concrete examples - with test data in the form of a datastep showing what you see. If for instance you want to keep all variables with varX (X being a number), then its simple to do var:, or you can do by position var1--var10. However if you have that many variables all named differently then I would have to suggest you have modeled the data badly, probably thinking in Excel terms, which is common and leads to tranposed datasets which are harder to work with in numerous ways - such as you are finding with specifying each column.
In terms of your second question, you can do:
data a; set b (in=b) x (in=x) c (in=y); if x then do; ... run;
Its very hard to tell from the zero information provided. But whilst you can use aliases with set, that just sets one dataset under the other, so makes no sense as x.fld is never going to be equal to y.fld, as neither comes from the same dataset. Aliases are used most when data is merged (joined per SQL).
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 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: