0% found this document useful (0 votes)
116 views8 pages

SAS Dataset Naming Rules

The document discusses SAS dataset, variable, and library naming rules and conventions. It states that names must start with a letter or underscore, can contain numbers but not as the first character, and cannot contain special characters except underscores. Names also cannot exceed 32 bytes. The document then demonstrates examples of valid and invalid dataset names based on these rules.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
116 views8 pages

SAS Dataset Naming Rules

The document discusses SAS dataset, variable, and library naming rules and conventions. It states that names must start with a letter or underscore, can contain numbers but not as the first character, and cannot contain special characters except underscores. Names also cannot exceed 32 bytes. The document then demonstrates examples of valid and invalid dataset names based on these rules.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

/* SAS Dataset Naming Rules:

--> Dataset Name Should start with Alphabets or underscore(_)


--> Dataset Name should not start with spl chars and numerics
--> Dataset name can contain numbers anywhere except 1st
position
--> Dataset name should not contain any spl chars anywhere
except underscore(_)
--> Dataset name should not exceed 32 bytes

SAS variable naming Rules:

--> variable Name Should start with Alphabets or underscore(_)


--> variable Name should not start with spl chars and numerics
--> variable name can contain numbers anywhere except 1st
position
--> variable name should not contain any spl chars anywhere
except underscore(_)
--> variable name should not exceed 32 bytes

Libref(Library Name) naming Rules:

--> Library Name Should start with Alphabets or underscore(_)


--> Library Name should not start with spl chars and numerics
--> Library name can contain numbers anywhere except 1st
position
--> Library name should not contain any spl chars anywhere
except underscore(_)
--> Library name should not exceed 8 bytes
*/

data Emp_data;
input EMP_ID $ Name $ Gender $ Dept $ Salary Temp;
datalines;
00105 Pranab Male IT 2500 +98.5
00108 Mira Female OPS 35000 -90.35
000105 Joyce Male SC 45000 +94.00
000108 Jane Female It 4000 93.54
run;
proc print;
run;

data Emp_data;
input EMP_ID Name $ Gender $ Dept $ Salary Temp;
datalines;
105 Pranab Male 2500 +98.5
Mira Female OPS 35000
105 Male SC +94.00
108 Jane It 4000 93.54
run;
proc print;
run;
/*
EMP_ID Name $ Gender $ Dept $ Salary Temp
105 pranab male 2500 98.5 .
105 male sc 94.00 108 .

*/

data Emp_data;
input EMP_ID Name $ Gender $ Dept $ Salary Temp;
datalines;
105 Pranab Male . 2500 +98.5
. Mira Female OPS 35000 .
105 . Male SC . +94.00
108 Jane . It 4000 93.54
run;
proc print;
run;
/*Invalid---->Starts with spl Char */
data @Example;
input EMP_ID Name $ Gender $ Dept $ Salary Temp;
datalines;
105 Pranab Male . 2500 +98.5
. Mira Female OPS 35000 .
105 . Male SC . +94.00
108 Jane . It 4000 93.54
run;
proc print;
run;
/*Invalid ---->Starts with Number*/
data 1Example;
input EMP_ID Name $ Gender $ Dept $ Salary Temp;
datalines;
105 Pranab Male . 2500 +98.5
. Mira Female OPS 35000 .
105 . Male SC . +94.00
108 Jane . It 4000 93.54
run;
proc print;
run;
/* Valid --->Starts with underscore(_)*/
data _Example;
input EMP_ID Name $ Gender $ Dept $ Salary Temp;
datalines;
105 Pranab Male . 2500 +98.5
. Mira Female OPS 35000 .
105 . Male SC . +94.00
108 Jane . It 4000 93.54
run;
proc print;
run;
/*Valid---->Starts with underscore and
we can use underscore anywhere in the datasetname*/
data _Exa_mple_;
input EMP_ID Name $ Gender $ Dept $ Salary Temp;
datalines;
105 Pranab Male . 2500 +98.5
. Mira Female OPS 35000 .
105 . Male SC . +94.00
108 Jane . It 4000 93.54
run;
proc print;
run;
/* Valid ---> Starts with Alphabet*/
data Example;
input EMP_ID Name $ Gender $ Dept $ Salary Temp;
datalines;
105 Pranab Male . 2500 +98.5
. Mira Female OPS 35000 .
105 . Male SC . +94.00
108 Jane . It 4000 93.54
run;
proc print;
run;

data Exa#mple123;
input EMP_ID Name $ Gender $ Dept $ Salary Temp;
datalines;
105 Pranab Male . 2500 +98.5
. Mira Female OPS 35000 .
105 . Male SC . +94.00
108 Jane . It 4000 93.54
run;
proc print;
run;

data Exa/mple123;
input EMP_ID Name $ Gender $ Dept $ Salary Temp;
datalines;
105 Pranab Male . 2500 +98.5
. Mira Female OPS 35000 .
105 . Male SC . +94.00
108 Jane . It 4000 93.54
run;
proc print;
run;

data Example123;
input EMP_ID Name $ Gender $ Dept $ Salary Temp;
datalines;
105 Pranab Male . 2500 +98.5
. Mira Female OPS 35000 .
105 . Male SC . +94.00
108 Jane . It 4000 93.54
run;
proc print;
run;

data _123Exa4567mple123;
input EMP_ID Name $ Gender $ Dept $ Salary Temp;
datalines;
105 Pranab Male . 2500 +98.5
. Mira Female OPS 35000 .
105 . Male SC . +94.00
108 Jane . It 4000 93.54
run;
proc print;
run;

data Employees_details;
input EMP_ID Name $ Gender $ Dept $ Salary Temp;
datalines;
105 Pranab Male . 2500 +98.5
. Mira Female OPS 35000 .
105 . Male SC . +94.00
108 Jane . It 4000 93.54
run;
proc print;
run;

data Employees details;


input EMP_ID Name $ Gender $ Dept $ Salary Temp;
datalines;
105 Pranab Male . 2500 +98.5
. Mira Female OPS 35000 .
105 . Male SC . +94.00
108 Jane . It 4000 93.54
run;
proc print;
run;

data Abc.Employees details1;


input EMP_ID Name $ Gender $ Dept $ Salary Temp;
datalines;
105 Pranab Male . 2500 +98.5
. Mira Female OPS 35000 .
105 . Male SC . +94.00
108 Jane . It 4000 93.54
run;
proc print;
run;
/*The data set name cannot have more than 32 bytes. */

data Employees_details123456789adsafsdgffgffdsgdshg;
input EMP_ID Name $ Gender $ Dept $ Salary Temp;
datalines;
105 Pranab Male . 2500 +98.5
. Mira Female OPS 35000 .
105 . Male SC . +94.00
108 Jane . It 4000 93.54
run;
proc print;
run;

data Employees_details123456789adsafs;
input EMP_ID Name $ Gender $ Dept $ Salary Temp;
datalines;
105 Pranab Male . 2500 +98.5
. Mira Female OPS 35000 .
105 . Male SC . +94.00
108 Jane . It 4000 93.54
run;
proc print;
run;

data Employees_details123456789adsafs;
input EMP_ID Name $ Gender $ Dept $ Salary Temp;
datalines;
105 Pranab Male . 2500 +98.5
. Mira Female OPS 35000 .
105 . Male SC . +94.00
108 Jane . It 4000 93.54
run;
proc print;
run;

/* SAS Libraries

Library: This is The physical location for all SAS Files


-- Datasets
-- Catalogs
-- Formats
-- Views
-- Utilities
Etc....

Libraries are 2 Types

-> SAS Defined Libraries

Temp - > Work


Perm - >SAShelp,SASuser,Mapssas....
These will be created by SAS Foundation
Maintained By SAS
U can't Delete these Libraries
-> User Defined Libraries

Perm -> These will be created by User


We Have Full Access on these libararies

How to create User Defined Library-->

Libname Libref(Libraryname) 'Location for library';

*/

Libname xyz "C:\Users\MAHIYA\Desktop\Ex\test";

Libname _xyz_ "C:\Users\MAHIYA\Desktop\Ex\test";

Libname _xyz_1234 "C:\Users\MAHIYA\Desktop\Ex\test";

Libname _xyz_123 "C:\Users\MAHIYA\Desktop\Ex\test";

/***********************************************************/
/* How to change Delimeter

Infile statement to declare the dlm option


Infile statemet--->Always Tells the source of the data
*/

data Emp_data;
infile datalines dlm=',';
input EMP_ID $ Name $ Gender $ Dept $ Salary Temp;
datalines;
105,Pranab,Male,IT,2500,+98.5
108,Mira,Female,OPS,35000,-90.35
105,Joyce,Male,SC,45000,+94.00
108,Jane,Female,It,4000,93.54
run;
proc print;
run;

data Emp_data;
infile datalines dlm=',';
input EMP_ID Name $ Gender $ Dept $ Salary Temp;
datalines;
105,Pranab,Male,IT,2500,
108, ,Female,OPS,35000,-90.35
105,Joyce,Male, ,45000,+94.00
,Jane,Female,It, ,93.54
run;
proc print;
run;
data Emp_data;
infile datalines dlm=',';
input EMP_ID Name $ Gender $ Dept $ Salary Temp;
datalines;
105,Pranab,Male,IT,2500,,, ,,,
108,,,,, ,,,,,Female,OPS,35000,-90.35
105,Joyce,Male,,,,, ,,,,45000,+94.00
,,, ,,Jane,Female,It,,,,,, ,,,,,,93.54
run;
proc print;
run;

* EMP_ID Name $ Gender $ Dept $ Salary Temp


105 pranab male it 2500 .
108 Female ops 35000 -90.35 105
;

data Emp_data;
infile datalines dlm=', ';
input EMP_ID Name $ Gender $ Dept $ Salary Temp;
datalines;
105,Pranab,Male,IT 2500,.
108,.,Female,OPS,35000,-90.35
105,Joyce,Male,.,45000,+94.00
.,Jane Female It,.,93.54
;
run;
proc print;
run;

* EMP_ID Name $ Gender $ Dept $ Salary Temp


105 pranab male it 2500 108
105 joyce male 45000 +94.00 .
;

data Emp_data;
infile cards dlm=',@#!()+$/*';
input EMP_ID $ Name $ Gender $ Dept $ Salary Temp;
cards;
105,#Pranab,$!@Male,IT,2500,+98.5
108,@Mira,Female,()OPS,35000,-90.35
105,/Joyce,Male,SC,45000,+94.00
108,Jane*,+-Female,It,4000,93.54
run;
proc print;
run;

data Emp_data;
input EMP_ID Name $ Gender $ Dept $ Salary Temp;
datalines;
105 Pranab Male IT 2500 +98.5
108 Mira Female OPS 35000A -90.35
105 Joyce Male SC 45t000 +94.00
108 Jane Female It 4000 93.54*
run;
proc print;
run;

data Emp_data1(Replace=No);
set sashelp.class;
run;
proc print;
run;

You might also like