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

Hello team,

I have this code:

data storm_cat;
set pg1.storm_summary;
keep Name Basin MinPressure StartDate PressureGroup;
*add ELSE keyword and remove final condition;
if MinPressure=. then PressureGroup=.;
else if MinPressure<=920 then PressureGroup=1;
else PressureGroup=0;
run;

PressureGroup is created after the keep statement. How does keep statement knows about
PressureGroup?

Your response is greatly appreciated.
GN

 

Blue Blue
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@GN0001 wrote:

Hello team,

I have this code:

data storm_cat;
set pg1.storm_summary;
keep Name Basin MinPressure StartDate PressureGroup;
*add ELSE keyword and remove final condition;
if MinPressure=. then PressureGroup=.;
else if MinPressure<=920 then PressureGroup=1;
else PressureGroup=0;
run;

PressureGroup is created after the keep statement. How does keep statement knows about
PressureGroup?

Your response is greatly appreciated.
GN

 


There are statements that SAS refers to as "Declaritive".

Declarative statements supply information to SAS and take effect when the system compiles program statements.

The order of most of these does not matter though the position may look "odd" in some contexts, especially if you get in a particular coding habit. Exceptions are Data (start a data step) Cards/Cards4/Datalines/Datalines4 which precede in-line data at the end of a step, and the End which ends a DO or Select block. Length may go anywhere but could generate some warnings about variables that exist.

Declarative Statements
ARRAY
DATALINES4
Labels, Statement
ATTRIB
DROP
LENGTH
BY
END
RENAME
CARDS
FORMAT
RETAIN
CARDS4
INFORMAT
WHERE
DATA
KEEP
WINDOW
DATALINES
LABEL

View solution in original post

3 REPLIES 3
ballardw
Super User

@GN0001 wrote:

Hello team,

I have this code:

data storm_cat;
set pg1.storm_summary;
keep Name Basin MinPressure StartDate PressureGroup;
*add ELSE keyword and remove final condition;
if MinPressure=. then PressureGroup=.;
else if MinPressure<=920 then PressureGroup=1;
else PressureGroup=0;
run;

PressureGroup is created after the keep statement. How does keep statement knows about
PressureGroup?

Your response is greatly appreciated.
GN

 


There are statements that SAS refers to as "Declaritive".

Declarative statements supply information to SAS and take effect when the system compiles program statements.

The order of most of these does not matter though the position may look "odd" in some contexts, especially if you get in a particular coding habit. Exceptions are Data (start a data step) Cards/Cards4/Datalines/Datalines4 which precede in-line data at the end of a step, and the End which ends a DO or Select block. Length may go anywhere but could generate some warnings about variables that exist.

Declarative Statements
ARRAY
DATALINES4
Labels, Statement
ATTRIB
DROP
LENGTH
BY
END
RENAME
CARDS
FORMAT
RETAIN
CARDS4
INFORMAT
WHERE
DATA
KEEP
WINDOW
DATALINES
LABEL
Cynthia_sas
SAS Super FREQ
Hi:
Please go back and review the videos that talk about the KEEP and DROP statements. The KEEP statement is setting a flag at compile time that tells SAS which variables need to be sent to the output dataset -- in this case, WORK.STORM_CAT. The variables you list in the KEEP or DROP statement can come from either the INPUT dataset (PG1.STORM_SUMMARY) or the OUTPUT dataset (WORK.STORM_CAT) or you can list variables that you create in the DATA step, (such as PressureGroup).

Order of the KEEP statement in the program does not matter. The program would work the same way no matter where the KEEP statement was positioned. We recommend putting "housekeeping" statements at the top of the program, but some people are in the habit of putting them at the bottom. It doesn't matter -- KEEP, DROP or WHERE statements can be positioned anywhere in a DATA step program.

Cynthia

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!

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
  • 3 replies
  • 728 views
  • 2 likes
  • 4 in conversation