Published on :
Général CREATION_INTERNE

Sans titre

This code is also available in: Deutsch Español Français
Awaiting validation
Data Analysis

Type : CREATION_INTERNE


Examples use generated data (datalines) or SASHELP.

1 Code Block
DATA STEP Data
Explanation :
This example creates a `mydata` dataset then defines a simple index on the SSN variable for the new `new` dataset.
Copied!
1DATA mydata;
2 INPUT ssn $ city $ state $;
3 DATALINES;
4123-45-6789 Raleigh NC
5987-65-4321 Cary NC
6111-22-3333 Apex NC
7444-55-6666 Durham NC
8123-45-6789 Raleigh NC
9. missing_city missing_state
10;
11RUN;
12 
13DATA new(index=(ssn));
14 SET mydata;
15RUN;
2 Code Block
DATA STEP Data
Explanation :
This example creates a `mydata` dataset then defines a composite index named CITYST, using the CITY and STATE variables for the new `new` dataset.
Copied!
1DATA mydata;
2 INPUT ssn $ city $ state $;
3 DATALINES;
4123-45-6789 Raleigh NC
5987-65-4321 Cary NC
6111-22-3333 Apex NC
7444-55-6666 Durham NC
8123-45-6789 Raleigh NC
9. missing_city missing_state
10;
11RUN;
12 
13DATA new(index=(cityst=(city state)));
14 SET mydata;
15RUN;
3 Code Block
DATA STEP Data
Explanation :
This example creates a `mydata` dataset then defines a simple index on SSN and a composite index on CITY and STATE for the new `new` dataset.
Copied!
1DATA mydata;
2 INPUT ssn $ city $ state $;
3 DATALINES;
4123-45-6789 Raleigh NC
5987-65-4321 Cary NC
6111-22-3333 Apex NC
7444-55-6666 Durham NC
8123-45-6789 Raleigh NC
9. missing_city missing_state
10;
11RUN;
12 
13DATA new(index=(ssn cityst=(city state)));
14 SET mydata;
15RUN;
4 Code Block
DATA STEP Data
Explanation :
This example creates a `mydata` dataset with unique SSNs then attempts to define a unique simple index for the SSN variable. Note that if duplicates are present in `ssn`, the index will not be built.
Copied!
1DATA mydata;
2 INPUT ssn $ city $ state $;
3 DATALINES;
4123-45-6789 Raleigh NC
5987-65-4321 Cary NC
6111-22-3333 Apex NC
7444-55-6666 Durham NC
8;
9RUN;
10 
11/* This will fail if there are duplicates in ssn (like '123-45-6789') */
12DATA new(index=(ssn /unique));
13 SET mydata;
14RUN;
5 Code Block
DATA STEP Data
Explanation :
This example creates a `mydata` dataset then defines a simple index for the SSN variable, excluding all observations with missing values from the index.
Copied!
1DATA mydata;
2 INPUT ssn $ city $ state $;
3 DATALINES;
4123-45-6789 Raleigh NC
5987-65-4321 Cary NC
6. missing_city missing_state
7111-22-3333 Apex NC
8;
9RUN;
10 
11DATA new(index=(ssn /nomiss));
12 SET mydata;
13RUN;
6 Code Block
DATA STEP Data
Explanation :
This example creates a `mydata` dataset then defines a unique and non-missing simple index for the SSN variable, and a unique and non-missing composite index named CITYST for the CITY and STATE variables. The UNIQUE and NOMISS options apply to each index specification.
Copied!
1DATA mydata;
2 INPUT ssn $ city $ state $;
3 DATALINES;
4123-45-6789 Raleigh NC
5987-65-4321 Cary NC
6111-22-3333 Apex NC
7. missing_city missing_state
8;
9RUN;
10 
11DATA new(index=(ssn /unique/nomiss cityst=(city state) /unique/nomiss));
12 SET mydata;
13RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.