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

Hello everyone,

 

In the first level of the practice dedicated to the first lesson of the second course, it is requested to create three tables : monument, park and other with the following conditions :

Drop Parktype for monument and park

Drop Region for the three tables.

 

The correct solution is :

data monument(drop=ParkType) park(drop=ParkType) other; 
    set pg2.np_yearlytraffic;
    if ParkType = 'National Monument' then output monument;
    else if ParkType = 'National Park' then output park;
    else output other;
    drop Region;
run;

But I tried to do it with "if then do" statements :

data monument park other;
	set pg2.np_yearlytraffic;
	drop Region;
	if ParkType = 'National Monument' then 
	do;
	drop Parktype;
	output monument;
	end;
	else if ParkType = 'National Park' then do;
	drop Parktype;
	output park;
	end;
	else output other;

run;

The issue being that now, the table other does not contain "Parktype" and I don't understand why is that so. 

 

Any help would be greatly appreciated.

Regards

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
Diamond | Level 26
Hi:
Please go back and review the material in Programming 2 on the DROP and KEEP statement. These statements cannot be executed conditionally. They are COMPILE time statements.
Cynthia

View solution in original post

2 REPLIES 2
Cynthia_sas
Diamond | Level 26
Hi:
Please go back and review the material in Programming 2 on the DROP and KEEP statement. These statements cannot be executed conditionally. They are COMPILE time statements.
Cynthia
maximek
Calcite | Level 5
thanks for your kind answer

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
LIBNAME 101

Follow along as SAS technical trainer Dominique Weatherspoon expertly answers all your questions about SAS Libraries.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 2027 views
  • 1 like
  • 2 in conversation