BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Phil_NZ
Barite | Level 11

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.

Thank you for your help, have a fabulous and productive day! I am a novice today, but someday when I accumulate enough knowledge, I can help others in my capacity.
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Indeed.

 

Though I did take a moment to say "use a small data set".

 

@Phil_NZ 

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>;

 

 

 

View solution in original post

5 REPLIES 5
ballardw
Super User

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.

Phil_NZ
Barite | Level 11

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!

Thank you for your help, have a fabulous and productive day! I am a novice today, but someday when I accumulate enough knowledge, I can help others in my capacity.
ballardw
Super User

Indeed.

 

Though I did take a moment to say "use a small data set".

 

@Phil_NZ 

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>;

 

 

 

FreelanceReinh
Jade | Level 19

@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

 
DATA view-name <(data-set-options)> <data-set-name-1 <(data-set-options-1)> > ...

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1372 views
  • 4 likes
  • 4 in conversation