Hi all SAS users,
I am starting using view, however, I read a couple of documents but can not find whether View should stand before or after the KEEP or DROP option.
For example, I have
data var_cal (drop=i);
set del_contries;
by gviidkey;
/*code*/
;
run;
I am wondering if I want to use view with data var_cal, what should I write the code?
data var_cal (drop=i) / view =var_cal;
/*or*/
data var_cal (drop=i) / view =var_cal(drop=i);
/*or*/
data var_cal / view =var_cal(drop=i);
I think the second code is more logical but I want to ask for your advice.
Warm regards.
Indeed.
Though I did take a moment to say "use a small data set".
When you think of a view as a set of instructions to build a result you maybe can see why certain options have to be limited.
You may have noticed that you can't mix names willy-nilly like
Data want / view=reallywant;
not every data set name on the DATA statement has to be a view but every view has to be a data set name. For instance:
data noname(drop=name) boys (where=(sex='M'))/ view=boys; set sashelp.class; run;
The documentation on the DATA statement describes your question. See all the data-set-options appear before the option / for the view.
Form 3:
DATA view-name <data-set-name-1 <(data-set-options-1)> >
<...data-set-name-n <(data-set-options-n)> > /
VIEW=view-name <(<password-option> <SOURCE=source-option> )>
<NESTING> <NOLIST>;
This is one of those cases where it may be a good idea to play with a very small data set and try different sets of syntax.
I think you will find that SAS tells you pretty quickly what is nice.
Hi @ballardw
Yes, I just worked out with sashelp. class. And from these three ways, only the first code work, I mean only this code work
data lll (drop=Age)/ view=lll ;
set sashelp.class;;
run;
It means that option DROP or KEEP cannot be written after view.
Error existed in those case
NOTE: Writing HTML5(EGHTML) Body file: EGHTML
27
28 data lll (drop=Age)/ view=lll(drop=Age) ;
____
22
76
ERROR 22-322: Syntax error, expecting one of the following: ALTER, EXECUTE, PROTECT, PW, READ, SOURCE, SRC, WRITE.
ERROR 76-322: Syntax error, statement will be ignored.
29 set sashelp.class;;
30 run;
ERROR: Unable to create WORK.LLL.DATA because WORK.LLL.VIEW already exists.
Do you agree with that, I hope I did not fall into a fallacy here, and any further notice for me as well?
Warmest regards.
Have a good day!
Indeed.
Though I did take a moment to say "use a small data set".
When you think of a view as a set of instructions to build a result you maybe can see why certain options have to be limited.
You may have noticed that you can't mix names willy-nilly like
Data want / view=reallywant;
not every data set name on the DATA statement has to be a view but every view has to be a data set name. For instance:
data noname(drop=name) boys (where=(sex='M'))/ view=boys; set sashelp.class; run;
The documentation on the DATA statement describes your question. See all the data-set-options appear before the option / for the view.
Form 3:
DATA view-name <data-set-name-1 <(data-set-options-1)> >
<...data-set-name-n <(data-set-options-n)> > /
VIEW=view-name <(<password-option> <SOURCE=source-option> )>
<NESTING> <NOLIST>;
@ballardw wrote:
(...)
The documentation on the DATA statement describes your question. See all the data-set-options appear before the option / for the view.
Form 3:DATA view-name <data-set-name-1 <(data-set-options-1)> >
<...data-set-name-n <(data-set-options-n)> > /
VIEW=view-name <(<password-option> <SOURCE=source-option> )>
<NESTING> <NOLIST>;
Actually it's not quite clear from this syntax pattern that dataset options can be specified for the view. I think it should read
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.