data work.difference (drop= goalamount); if _N_ = 1 then do; declare hash goal( ); goal.definekey("QtrNum"); goal.definedata("GoalAmount"); goal.definedone( ); call missing(goalamount); goal.add(key:'qtr1', data:10 ); goal.add(key:'qtr2', data:15 ); goal.add(key:'qtr3', data: 5 ); goal.add(key:'qtr4', data:15 ); end; set sasuser.contrib; goal.find(); Diff = amount - goalamount; run;
General form, DECLARE
statement:
DECLARE object-name <(<argument_tag-1:
value-1<,
...argument_tag-n: value-n>>)>;
object
specifies the component
object.
object-name
specifies the name
for the component object.
arg_tag
specifies the information
that is used to create an instance of the component object.
value
specifies the value
for an argument tag. Valid values depend on the component object.
Valid values for object are
as follows:
|
data work.difference (drop= goalamount);
if _N_ = 1 then do;
declare hash goal();
General form, object
dot notation method calls:
object.method(<argument_tag-1:
value-1<,
...argument_tag-n: value-n>>);
object
specifies the name
for the DATA step component object.
method
specifies the name
of the method to invoke.
argument-tag
identifies the arguments
that are passed to the method.
value
specifies the argument
value.
|
data work.difference (drop= goalamount); length goalamount 8; if _N_ = 1 then do; declare hash goal(); goal.definekey ("QtrNum"); goal.definedata ("GoalAmount"); goal.definedone();
data Work.Difference (drop= goalamount);
if _N_ = 1 then do; declare hash goal();
goal.definekey("QtrNum");
goal.definedata("GoalAmount");
goal.definedone();
call missing(goalamount);
data work.difference (drop= goalamount); if _N_ = 1 then do; declare hash goal( ); goal.definekey("QtrNum"); goal.definedata("GoalAmount"); goal.definedone( ); call missing(goalamount); goal.add(key:'qtr1', data:10 ); goal.add(key:'qtr2', data:15 ); goal.add(key:'qtr3', data: 5 ); goal.add(key:'qtr4', data:15 ); end;
data work.difference (drop= goalamount);
if _N_ = 1 then do;
declare hash goal( );
goal.definekey("QtrNum");
goal.definedata("GoalAmount");
goal.definedone( );
call missing(goalamount);
goal.add(key:'qtr1', data:10 );
goal.add(key:'qtr2', data:15 );
goal.add(key:'qtr3', data: 5 );
goal.add(key:'qtr4', data:15 );
end;
set sasuser.contrib;
rc=goal.find();
Diff = amount - goalamount;
run;
data Work.Difference (drop= goalamount);
if _N_ = 1 then do;
declare hash goal( );
goal.definekey("QtrNum");
goal.definedata("GoalAmount");
goal.definedone( );
call missing(goalamount);
goal.add(key:'qtr1', data:10 );
goal.add(key:'qtr2', data:15 );
goal.add(key:'qtr3', data: 5 );
goal.add(key:'qtr4', data:15 );
end;
set sasuser.contrib;
rc=goal.find();
Diff = amount - goalamount;
run;
Origin
|
Dest
|
FlightID
|
Date
|
Rev1st
|
RevBusiness
|
RevEcon
|
---|---|---|---|---|---|---|
ANC
|
RDU
|
IA03400
|
02DEC1999
|
15829
|
28420
|
68688
|
ANC
|
RDU
|
IA03400
|
14DEC1999
|
20146
|
26460
|
72981
|
ANC
|
RDU
|
IA03400
|
26DEC1999
|
20146
|
23520
|
59625
|
ANC
|
RDU
|
IA03401
|
09DEC1999
|
15829
|
22540
|
58671
|
ANC
|
RDU
|
IA03401
|
21DEC1999
|
20146
|
22540
|
65826
|
City
|
Code
|
Name
|
Country
|
---|---|---|---|
Auckland
|
AKL
|
International
|
New Zealand
|
Amsterdam
|
AMS
|
Schiphol
|
Netherlands
|
Anchorage, AK
|
ANC
|
Anchorage International
Airport
|
USA
|
Stockholm
|
ARN
|
Arlanda
|
Sweden
|
Athens (Athinai)
|
ATH
|
Hellinikon International
Airport
|
Greece
|
data work.report; if _N_=1 then do; declare hash airports (dataset: "sasuser.acities");
data work.report; if _N_=1 then do; if 0 then set sasuser.acities (keep=Code City Name);
data work.report; if 0 then set sasuser.acities (keep=Code City Name); if _N_=1 then do; declare hash airports (dataset: "sasuser.acities") airports.definekey ("Code"); airports.definedata ("City", "Name"); airports.definedone(); end;
Key: Code
|
Data: City
|
Data: Name
|
---|---|---|
ANC
|
Anchorage, AK
|
Anchorage International
Airport
|
BNA
|
Nashville, TN
|
Nashville International
Airport
|
CDG
|
Paris
|
Charles de Gaulle
|
LAX
|
Los Angeles, CA
|
Los Angeles International
Airport
|
RDU
|
Raleigh-Durham, NC
|
Raleigh-Durham International
Airport
|
data work.report; if _N_=1 then do; if 0 then set sasuser.acities (keep=Code City Name); declare hash airports (dataset: "sasuser.acities"); airports.definekey ("Code"); airports.definedata ("City", "Name"); airports.definedone(); end; set sasuser.revenue; rc=airports.find(key:origin); OriginCity=city; OriginAirport=name; rc=airports.find(key:dest); DestCity=city; DestAirport=name; run;
proc print data=work.report; var origin dest flightid date origincity originairport destcity destairport; run;
0
indicates
that the method succeeded. A nonzero value indicates that the method
failed.
rc=hashobject.find (key:keyvalue);
data work.report; if _N_=1 then do; if 0 then set sasuser.acities (keep=Code City Name); declare hash airports (dataset: "sasuser.acities"); airports.definekey ("Code"); airports.definedata ("City", "Name"); airports.definedone(); end; set sasuser.revenue; airports.find(key:origin); OriginCity=city; OriginAirport=name; airports.find(key:dest); DestCity=city; DestAirport=name; run;
NOTE: There were 50 observations read from the data set SASUSER.ACITIES. ERROR: Key not found. ERROR: Key not found. ERROR: Key not found. ERROR: Key not found. ERROR: Key not found. ERROR: Key not found. NOTE: The SAS System stopped processing this step because of errors. NOTE: There were 142 observations read from the data set SASUSER.REVENUE. WARNING: The data set WORK.REPORT1 may be incomplete. When this step was stopped there were 142 observations and 14 variables. |
Canberra, Australian
C
and the values of OriginAirport and DestAirport
are missing.
0
, indicating
that the method succeeded, the values of City and Name are assigned
to the appropriate variables (OriginCity and OriginAirport or DestCity
and DestAirport).
data work.report; if _N_=1 then do; if 0 then set sasuser.acities(keep=Code City Name); declare hash airports (dataset: "sasuser.acities"); airports.definekey ("Code"); airports.definedata ("City", "Name"); airports.definedone(); end; set sasuser.revenue; rc=airports.find(key:origin); if rc=0 then do; OriginCity=city; OriginAirport=name; end; else do; OriginCity=''; OriginAirport=''; end; rc=airports.find(key:dest); if rc=0 then do; DestCity=city; DestAirport=name; end; else do; DestCity=''; DestAirport=''; end; run;
proc print data=work.report; var origin dest flightid date origincity originairport destcity destairport; run;