BookmarkSubscribeRSS Feed
ariyurjana
Obsidian | Level 7

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

3 REPLIES 3
error_prone
Barite | Level 11
Use the keep-statement to control which variables are written to the output-datasets.
If you use more the one dataset in SET the datasets are append, maybe you need a merge to get what you want. And, no, the concept of aliasing does not exist in the data-step.
ariyurjana
Obsidian | Level 7

@error_prone thanks for your reply I was hoping there would be some way out.

regards

jana

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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).

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 659 views
  • 0 likes
  • 3 in conversation