![]() | ![]() | ![]() | ![]() | ![]() |
Note:
For detailed information regarding object dot programming
in the DATA step, please refer to
SAS 9.2 Language
Reference: Concepts, Using DATA Step Component Objects.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
/* Create sample data WORK.CAPS and WORK.TEST */
data caps;
infile datalines truncover;
input cap $15.;
datalines;
DATA
SAS
_NEW_
ADD
;
options linesize=130;
data test;
infile datalines truncover;
input c $125.;
datalines;
The data step is very powerful. the data step has been part of sas since at least 1976.
Using dot notation makes your sas programs easier to read.
Use the _new_ statement to instantiate an object.
You can use the add method in one of two ways to store data in a hash object.
;
/* Use the CHECK method to determine whether the UPCASE version of the word pulled */
/* from C is stored in the hash object H. A return code of zero indicates the key */
/* was found. */
data upcased;
set test;
length cap $ 15;
/* On the first iteration of the DATA step, create and instantiate a hash */
/* table called H. Use the DATASET: argument tag to load WORK.CAPS into */
/* H. H will contain CAP, the key variable that is used to find a match. */
/* CAP is also defined as 'data' so it will be part of the output data set. */
/* A KEY is not output by default. */
if _n_ = 1 then do;
declare hash h(dataset: "work.caps");
h.definekey('cap');
h.definedata('cap');
h.definedone();
/* Use CALL MISSING to avoid a 'variable is uninitialized' message in */
/* the SAS log. */
call missing(cap);
end;
length final $ 125;
/* NUMW equals the number of words in the variable C */
numw=countc(trim(c),' ')+1;
/* SCAN off each word from C. Use the CHECK method to see if the upcased */
/* version of TEMP is matched. If a match is found, the return code is 0. */
/* For successful matches, use CATX to concatenate FINAL with the upper- */
/* case version of TEMP, separated by a space and assign the result into */
/* FINAL. If a match is not found, use CATX to concatenate FINAL with the */
/* lowercase version of TEMP, separated by a space. */
do i=1 to numw;
temp=scan(c,i,' ');
if h.check(key:upcase(temp))=0 then final=catx(' ',final,upcase(temp));
else do;
if i=1 or indexc(scan(c,i-1,' '),',.;:') ne 0 then final=catx(' ',final,propcase(temp));
else final=catx(' ',final,lowcase(temp));
end;
end;
keep final;
run;
proc print;
run;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Obs final 1 The DATA step is very powerful. The DATA step has been part of SAS since at least 1976. 2 Using dot notation makes your SAS programs easier to read. 3 Use the _NEW_ statement to instantiate an object. 4 You can use the ADD method in one of two ways to store DATA in a hash object.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Component Objects ==> hash object ==> CHECK SAS Reference ==> Component Objects ==> hash object ==> DEFINEDATA SAS Reference ==> Component Objects ==> hash object ==> DEFINEDONE SAS Reference ==> Component Objects ==> hash object ==> DEFINEKEY |
| Date Modified: | 2006-05-27 03:03:00 |
| Date Created: | 2005-11-02 13:43:34 |
| Product Family | Product | Host | SAS Release | |
| Starting | Ending | |||
| SAS System | Base SAS | Tru64 UNIX | 9.1 TS1M0 | n/a |
| Linux | 9.1 TS1M0 | n/a | ||
| Solaris | 9.1 TS1M0 | n/a | ||
| HP-UX IPF | 9.1 TS1M0 | n/a | ||
| HP-UX | 9.1 TS1M0 | n/a | ||
| 64-bit Enabled Solaris | 9.1 TS1M0 | n/a | ||
| AIX | 9.1 TS1M0 | n/a | ||
| 64-bit Enabled HP-UX | 9.1 TS1M0 | n/a | ||
| 64-bit Enabled AIX | 9.1 TS1M0 | n/a | ||
| Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.1 TS1M0 | n/a | ||
| OpenVMS Alpha | 9.1 TS1M0 | n/a | ||
| z/OS | 9.1 TS1M0 | n/a | ||




