0% found this document useful (0 votes)
113 views19 pages

Stansys: Software Solutions

Data types, lengths, and labels provide important metadata for variables. Data types indicate whether variable values are character or numeric. Length specifies the number of bytes for storing values. Labels assign descriptive names to variables. Together, these attributes help define, organize, and understand the structure and meaning of variable data.

Uploaded by

nagap1914
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
113 views19 pages

Stansys: Software Solutions

Data types, lengths, and labels provide important metadata for variables. Data types indicate whether variable values are character or numeric. Length specifies the number of bytes for storing values. Labels assign descriptive names to variables. Together, these attributes help define, organize, and understand the structure and meaning of variable data.

Uploaded by

nagap1914
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

ATTRIBUTES OF VARIABLES

Data type
Length
Label
Informat
Formats

DATATYPE
Indicates variable values are Character or Numeric data type.
If you specify $ symbol after the variable that is character data otherwise numeric data.
If you won’t specify $ symbol for character variable system thinks that is a numeric
variable but contains character data so output dataset contains missing value as period.
Character variable will read both character and numeric data. But numeric variable will
read only numeric data.
In dataset character data is left aligned, Numeric data is right aligned.
Example:-
Data DS;
Infile datalines;
Input id name$ sex$ age sal;
Datalines;
001 Ronald m 23 50000
002 Clark f 22 34500
003 Roopa f 26 45000
;
Run;

LENGTH STATEMENT
Specifies the number of bytes for storing variable values.
We can assign length for variables.
Syntax: - LENGTH variable(s)<$>length
Examples:-
Data DS1;
Length name $17.;
Infile datalines;
Input id name$ sex$ age sal ;
79

Datalines;
001 Ronaldregon m 23 50000
Page

002 Michaleclark f 22 34500


003 Roopasubramanyam f 26 45000
;
Run;
Data ds2;
Length name $10.;
Set ds1;
Run;

__________________________________________________________________________________________
STANSYS SOFTWARE SOLUTIONS
#7-1-621/113(67/3RT), Beside: Nagarjuna High School, Near: S.R.Nagar Community Hall,
S.R.Nagar, Hyd-38|Ph:9542195422/7671076710|www.stansys.co.in|[email protected]
Length statement always should write before Input or before
Set statement or before variable. Otherwise when input
executes whatever the length is there(default is 8) that will
come into output.

LABEL STATEMENT
Assigns descriptive labels to variables.
Assign alias names to variables.
Label can’t change the column name permanently like rename
Syntax: - LABEL variable-1='label-1' . . . <variable-n='label-n'>;
LABEL variable-1=' ' . . . <variable-n=' '>;
Data DS1;
Infile datalines;
Input id name$ sex$ age sal;
Label name='Emp Name' sex='Gender' sal='Income';
Datalines;
001 Ronald m 23 50000
002 Clark f 22 34500
003 Roopa f 26 45000
;
Run;
Data DS2;
Infile datalines;
Label name='Emp Name' sex='Gender' sal='Income';
Input id name$ sex$ age sal;
Datalines;
001 Ronald m 23 50000
002 Clark f 22 34500
003 Roopa f 26 45000
;
Run;
If we write Label statement after input statement output dataset will be in input order
But if we write before input, output dataset order should be in label order then what ever
variable is not there in label those will come in input order
If we specify label is ' ' raw data variable name should come into output dataset.
Means below example Label name=' ' so output dataset contains existing variable is
80

name
Page

Data DS3;
Infile datalines;
Input id name$ sex$ age sal;
Label name=' ' sex='Gender' sal=' ';
Datalines;
001 Ronald m 23 50000
002 Clark f 22 34500
003 Roopa f 26 45000
;
Run;
__________________________________________________________________________________________
STANSYS SOFTWARE SOLUTIONS
#7-1-621/113(67/3RT), Beside: Nagarjuna High School, Near: S.R.Nagar Community Hall,
S.R.Nagar, Hyd-38|Ph:9542195422/7671076710|www.stansys.co.in|[email protected]
INFORMAT STATEMENT
Informat is an instruction that SAS uses to read data
values into a variable.
Informats are usually specified in an input statement. If
coded with the informat statements, attach an informat to a variable for subsequent
input.
Informats can be user-written Informats also.
Syntax: - INFORMAT variable-1<informat-1> variable-N<informat-N>;
Categories of Informats:-
1. Character Informats
2. Numeric Informats
3. Date, Time, Datetime Informats
4. Column binary Informats
5. User defined Informats

Character Informats: -
Reads character data into character variables.
Syntax: - informatw.
Ex: - $
$10.
$20.
$Char10.
Examples:-
Data infmt6;
Input id name$ age sex$ sal;
Datalines;
001 David 23 m 50000
002 Amelia 32 f 25000
003 Alan 31 f 30000
004 Ravi 21 m 45000
005 Jim 35 f 28000
;
Run;
Data informat6a;
Input idno name & $18. team$ strtwght endwght;
Datalines;
81

1023 David Shaw red 189 165


1049 Amelia Serrano yellow 145 124
Page

1219 Alan Nance red 210 192


1246 Ravi Sinha yellow 194 177
1078 Ashley McKnight red 127 118
1221 Jim Brown yellow 220 .
;
Run;

Numeric Informats: -
Reads numeric data values from numeric variables
Syntax: - informatw.d
__________________________________________________________________________________________
STANSYS SOFTWARE SOLUTIONS
#7-1-621/113(67/3RT), Beside: Nagarjuna High School, Near: S.R.Nagar Community Hall,
S.R.Nagar, Hyd-38|Ph:9542195422/7671076710|www.stansys.co.in|[email protected]
Ex: - Comma12. Dollar10.2
Examples:-
Data infmt1;
Infile datalines;
Input id name$ age sex$ sal;
Datalines;
001 David 23 m 50000
002 Amelia 32 f 25000
003 Alan 31 f 30000
004 Ravi 21 m 45000
005 Jim 35 f 28000
;
Run;
In above example data and columns are same data type so you can read. But see below program
sal values are containing special character but sal variable is numeric so you can’t read data in
this case we can specify informat to read data, not only with comma when numeric data contains
special characters like comma, dollar, euro we can specify Numeric Informats like below.
Data infmt2;
Infile datalines;
Input id name$ age sex$ sal comma6.;
Datalines;
001 David 23 m 50,000
002 Amelia 32 f 25,000
003 Alan 31 f 30,000
004 Ravi 21 m 45,000
005 Jim 35 f 28,000
;
Run
Data infmt3;
Infile datalines;
Input id name$ age sex$ sal;
Informat sal comma6. ;
Datalines;
001 David 23 m 50,000
002 Amelia 32 f 25,000
003 Alan 31 f 30,000
004 Ravi 21 m 45,000
005 Jim 35 f 28,000
82

Run;
Data infmt4;
Page

Infile datalines;
Input id name$ age sex$ sal dollar5. ;
Datalines;
001 David 23 m $5000
002 Amelia 32 f $2500
003 Alan 31 f $3000
004 Ravi 21 m $4500
005 Jim 35 f $28000
;
Run;
__________________________________________________________________________________________
STANSYS SOFTWARE SOLUTIONS
#7-1-621/113(67/3RT), Beside: Nagarjuna High School, Near: S.R.Nagar Community Hall,
S.R.Nagar, Hyd-38|Ph:9542195422/7671076710|www.stansys.co.in|[email protected]
Data infmt5;
Infile datalines; Informat we can
write with Input
Input id name$ age sex$ sal dollar6. ; statement after
the variable or we can
/*Informat sal dollar6. ;*/ write as a separate statement like this
Datalines;
001 David 23 m $5,000
002 Amelia 32 f $2,500
003 Alan 31 f $3,000
004 Ravi 21 m $4,500
005 Jim 35 f $2,800
;
Run;
Data infmt6;
Infile datalines;
Input id name$ age sex$ sal dollar9.2 ;
Format sal dollar10.2;
Datalines;
001 David 23 m $50000.55
002 Amelia 32 f $25000.00
003 Alan 31 f $30000.05
004 Ravi 21 m $45000.07
005 Jim 35 f $28000.99
;
Run;

Date,time and Datetime Informats:-


Reads data values into variables representing time, dates and date times.
Syntax: - informatw.
Date7. 29Jan10
Date9.   29Jan2010
  ddmmyy8.   29/01/10 29-01-10 29:01:10
  ddmmyy10.    29/01/2010 29-01-2010 29:01:2010
  Anydtdte. If u don’t know about date informat then you can use this
  Time.   10:30:20
  Datetime.   29Jan10:10:30:20
83

Examples:-
Page

Data infmt7;
Infile datalines;
Input id name$ age sex$ sal dob;
Datalines;
001 David 23 m 50000 10Feb1983
002 Amelia 32 f 25000 15May1984
003 Alan 31 f 30000 21Jul1984
004 Ravi 21 m 45000 05Aug1984
005 Jim 35 f 28000 30Jan1985
;
__________________________________________________________________________________________
STANSYS SOFTWARE SOLUTIONS
#7-1-621/113(67/3RT), Beside: Nagarjuna High School, Near: S.R.Nagar Community Hall,
S.R.Nagar, Hyd-38|Ph:9542195422/7671076710|www.stansys.co.in|[email protected]
Run;
In SAS dates are Numeric data type but DOB values contains
character values in above example, so we can’t read, to read
dates we should use date informats like below
Data infmt7a;
Infile datalines;
Input id name$ age sex$ sal dob date9.;
/*Informat dob date9.;*/
Datalines;
001 David 23 m 50000 10Feb1983
002 Amelia 32 f 25000 15May1984
003 Alan 31 f 30000 21Jul1984
004 Ravi 21 m 45000 05Aug1984
005 Jim 35 f 28000 30Jan1985
;
Run;
Data infmt7b;
Infile datalines;
Input id name$ age sex$ sal dob date7.;
/*Informat dob date7.;*/
Datalines;
001 David 23 m 50000 10Feb83
002 Amelia 32 f 25000 15May84
003 Alan 31 f 30000 21Jul84
004 Ravi 21 m 45000 05Aug84
005 Jim 35 f 28000 30Jan85
;
Run;
Data infmt7c;
Infile datalines;
Input id name$ age sex$ sal dob anydtdte.;
/*Informat dob date9.;*/
Datalines;
001 David 23 m 50000 10Feb1983
002 Amelia 32 f 25000 15May1984
003 Alan 31 f 30000 21Jul1984
004 Ravi 21 m 45000 05Aug1984
005 Jim 35 f 28000 30Jan1985
84

;
Run;
Page

Data infmt8;
Infile datalines;
Input id name$ age sex$ sal dob date9. doj:ddmmyy10. ;
/*Input id name$ age sex$ sal dob anydtdte9. doj:anydtdte10.;*/
Datalines;
001 David 23 m 50000 10Feb1983 12/01/2011
002 Amelia 32 f 25000 15May1984 15/01/2011
003 Alan 31 f 30000 21Jul1984 31/01/2011
004 Ravi 21 m 45000 05Aug1984 25/02/2011

__________________________________________________________________________________________
STANSYS SOFTWARE SOLUTIONS
#7-1-621/113(67/3RT), Beside: Nagarjuna High School, Near: S.R.Nagar Community Hall,
S.R.Nagar, Hyd-38|Ph:9542195422/7671076710|www.stansys.co.in|[email protected]
005 Jim 35 f 28000 30Jan1985 08/03/2011
;
Run;
Data infmt8a;
Infile datalines;
Input id name$ age sex$ sal dob date9. doj:ddmmyy8. ;
/*Informat dob date9. doj ddmmyy8.;*/
Datalines;
001 David 23 m 50000 10Feb1983 12/01/11
002 Amelia 32 f 25000 15May1984 15/01/11
003 Alan 31 f 30000 21Jul1984 31/01/11
004 Ravi 21 m 45000 05Aug1984 25/02/11
005 Jim 35 f 28000 30Jan1985 08/03/11
;
Run;
Data infmt8b;
Infile datalines;
Input id name$ age sex$ sal dob doj;
Informat dob date9. doj ddmmyy10.;
Datalines;
001 David 23 m 50000 10Feb1983 12/01/2011
002 Amelia 32 f 25000 15May1984 15/01/2011
003 Alan 31 f 30000 21Jul1984 31/01/2011
004 Ravi 21 m 45000 05Aug1984 25/02/2011
005 Jim 35 f 28000 30Jan1985 08/03/2011
;
Run;
Data infmt9;
Infile datalines;
Input id name$ age sex$ sal dob datetime.;
Datalines;
001 David 23 m 50000 10Feb1983:10:30:15
002 Amelia 32 f 25000 15May1984:11:23:23
003 Alan 31 f 30000 21Jul1984:08:34:45
004 Ravi 21 m 45000 05Aug1984:12:43:56
005 Jim 35 f 28000 30Jan1985:03:35:12
;
Run;
85

Data infmt9a;
Input id name$ age sex$ sal dob ;
Page

Informat dob time.;


Datalines;
001 David 23 m 50000 10:30:15
002 Amelia 32 f 25000 11:23:23
003 Alan 31 f 30000 08:34:45
004 Ravi 21 m 45000 12:43:56
005 Jim 35 f 28000 03:35:12
;
Run;
Column binary Informats:-
__________________________________________________________________________________________
STANSYS SOFTWARE SOLUTIONS
#7-1-621/113(67/3RT), Beside: Nagarjuna High School, Near: S.R.Nagar Community Hall,
S.R.Nagar, Hyd-38|Ph:9542195422/7671076710|www.stansys.co.in|[email protected]
Reads data stored in column- binary or multi –punched form
into character and numeric variables
Ex: - row 12.3, $ cd4.

User defined Informats:-


Created by using proc format.
Programmer can create his own informats to read the data using Proc Format.
Proc format;
Invalue $team 'blue'=1
'green'=2
'red'=3
'yellow'=4;
Run;
Data ds;
Infile datalines;
Input idno name&$18. Team $ strtwght endwght ;
Informat team$ team.;
Datalines;
1331 Jason Schock Long blue 187 172
1067 Kanoko Nagasaka green 135 122
1251 Richard Rose blue 181 166
1192 Charlene Armstrong yellow 152 139
1352 Bette Long Schock green 156 137
1262 Yao Chen Garg blue 196 180
1124 Adrienne Fink green 156 142
;
Run;

FORMAT STATEMENT
Format is an instruction that SAS uses to write data values.
The format is exactly the same as that for informat.
Infact most SAS defined informats are also SAS defined formats.
However there are some informats such as anydtdte.
That is not defined as Format
Syntax: - FORMAT variable-1<format-1> variable-N<format-N>;
86

Categories of Formats:-
Page

1. Character Formats
2. Numeric Formats
3. Date, Time, Datetime Formats
4. Column binary Formats
5. User defined Formats

Character Formats: -
Writes character data values from character variables
__________________________________________________________________________________________
STANSYS SOFTWARE SOLUTIONS
#7-1-621/113(67/3RT), Beside: Nagarjuna High School, Near: S.R.Nagar Community Hall,
S.R.Nagar, Hyd-38|Ph:9542195422/7671076710|www.stansys.co.in|[email protected]
Character informats and character formats both are same
Syntax: - $ formatw.
Ex: - $
$10.
$20.
$char10.
Examples:-
Data fmt5;
Infile datalines;
Input id name$ age sex$ sal;
Datalines;
001 David 23 m 50000
002 Amelia 32 f 25000
003 Alan 31 f 30000
004 Ravi 21 m 45000
005 Jim 35 f 28000
;
Run;
Data fmt5a;
Infile datalines;
Input idno name & $18. team$ strtwght endwght;
Datalines;
1023 David Shaw red 189 165
1049 Amelia Serrano yellow 145 124
1219 Alan Nance red 210 192
1246 Ravi Sinha yellow 194 177
1078 Ashley McKnight red 127 118
1221 Jim Brown yellow 220 .
;
Run;

Numeric Formats: -
Writes numeric data values from numeric variables.
Syntax: - formatw.d
Ex: - Dollar10.
Dollar 10.2
87

Comma10.
Comma10.2
Page

Percent 4.2
Best10.
Examples:-
Data fmt1;
Infile datalines;
Input id name$ age sex$ sal comma6.;
Format sal comma6.;
/*Format sal comma9.2;*/
Datalines;
__________________________________________________________________________________________
STANSYS SOFTWARE SOLUTIONS
#7-1-621/113(67/3RT), Beside: Nagarjuna High School, Near: S.R.Nagar Community Hall,
S.R.Nagar, Hyd-38|Ph:9542195422/7671076710|www.stansys.co.in|[email protected]
001 David 23 m 50,000
002 Amelia 32 f 25,000
003 Alan 31 f 30,000
004 Ravi 21 m 45,000
005 Jim 35 f 28,000
;
Run;
Data fmt2;
Infile datalines;
Input id name$ age sex$ sal;
Informat sal comma9.2;
Format sal comma9.2;
Datalines;
001 David 23 m 50,000.55
002 Amelia 32 f 25,000.00
003 Alan 31 f 30,000.60
004 Ravi 21 m 45,000.77
005 Jim 35 f 28,000.50
;
Run;
Data fmt3;
Infile datalines;
Input id name$ age sex$ sal dollar5. ;
Format sal dollar5.;
Datalines;
001 David 23 m $5000
002 Amelia 32 f $2500
003 Alan 31 f $3000
004 Ravi 21 m $4500
005 Jim 35 f $28000
;
Run;
Data fmt3a;
Infile datalines;
Input id name$ age sex$ sal dollar6. ;
/*Format sal dollar6.;*/
Format sal dollar9.2;
/*Format sal comma6.;*/
88

Datalines;
001 David 23 m $5,000
Page

002 Amelia 32 f $2,500


003 Alan 31 f $3,000
004 Ravi 21 m $4,500
005 Jim 35 f $2,000
;
Run;
Date, Time and Datetime Formats: -
Write data values from variables representing Time, date and date time variables.
Syntax: - formatw.
__________________________________________________________________________________________
STANSYS SOFTWARE SOLUTIONS
#7-1-621/113(67/3RT), Beside: Nagarjuna High School, Near: S.R.Nagar Community Hall,
S.R.Nagar, Hyd-38|Ph:9542195422/7671076710|www.stansys.co.in|[email protected]
date7. 29Jan10
date9.

  29Jan2010
  ddmmyy8.
  29/01/10
  ddmmyy10.
   29/01/2010
  time5.   10:30
  time8.   10:30:20
  datetime.   29Jan10:10:30:20
  datetime20.   29Jan2010:10:30:20
  worddate20.   January 29, 2010
  weekdate30.   Friday, January 29,2010
  yymmddn8.   20100129
  yymmddd8.   10-01-29
  yymmddd10.    2010-01-29
  yymmdds8.   10/01/29
yymmdds10. 2010/01/29
yymmddc8 10:01:29
Yymmddc10. 2010:01:29

Examples:-
Data fmt6;
Infile datalines;
Input id name$ age sex$ sal dob date9.;
Format dob date9.;
/*Format dob date7.;*/
/*Format dob date9.;*/
/*Format dob ddmmyy8.;*/
/*Format dob ddmmyy10.;*/
/*Format dob worddate20.;*/
/*Format dob weekdate30.;*/
89

/*Format dob yymmddN8.;*/


Page

/*Format dob yymmddS8.;*/


/*Format dob yymmddS10.;*/
/*Format dob yymmddD8.;*/
/*Format dob yymmddD10.;*/
/*Format dob yymmddC8.;*/
/*Format dob yymmddC10.;*/
Datalines;
001 David 23 m 50000 10Feb1983
002 Amelia 32 f 25000 15May1984
003 Alan 31 f 30000 21Jul1984

__________________________________________________________________________________________
STANSYS SOFTWARE SOLUTIONS
#7-1-621/113(67/3RT), Beside: Nagarjuna High School, Near: S.R.Nagar Community Hall,
S.R.Nagar, Hyd-38|Ph:9542195422/7671076710|www.stansys.co.in|[email protected]
004 Ravi 21 m 45000 05Aug1984
005 Jim 35 f 28000 30Jan1985
;
Run;
Data fmt7;
Infile datalines;
Input id name$ age sex$ sal dob date9. doj:ddmmyy10. ;
Format dob worddate20. doj weekdate30.;
Datalines;
001 David 23 m 50000 10Feb1983 12/01/2011
002 Amelia 32 f 25000 15May1984 15/01/2011
003 Alan 31 f 30000 21Jul1984 31/01/2011
004 Ravi 21 m 45000 05Aug1984 25/02/2011
005 Jim 35 f 28000 30Jan1985 08/03/2011
;
Run;
Data fmt8;
Infile datalines;
Input id name$ age sex$ sal dob ;
Informat dob datetime.;
Format dob datetime.;
/*Format dob datetime20.;*/
Datalines;
001 David 23 m 50000 10Feb1983:10:30:15
002 Amelia 32 f 25000 15May1984:11:23:23
003 Alan 31 f 30000 21Jul1984:08:34:45
004 Ravi 21 m 45000 05Aug1984:12:43:56
005 Jim 35 f 28000 30Jan1985:03:35:12
;
Run;
Data fmt9;
Infile datalines;
Input id name$ age sex$ sal dob ;
Informat dob time.;
Format dob time.;
/*Format dob time8.;*/
/*Format dob time5.;*/
90

Datalines;
001 David 23 m 50000 10:30:15
Page

002 Amelia 32 f 25000 11:23:23


003 Alan 31 f 30000 08:34:45
004 Ravi 21 m 45000 12:43:56
005 Jim 35 f 28000 03:35:12
;
Run;

Column binary Formats: -


Writes data stored in column- binary or multi –punched form into character and numeric
variables.
__________________________________________________________________________________________
STANSYS SOFTWARE SOLUTIONS
#7-1-621/113(67/3RT), Beside: Nagarjuna High School, Near: S.R.Nagar Community Hall,
S.R.Nagar, Hyd-38|Ph:9542195422/7671076710|www.stansys.co.in|[email protected]
Ex: - row 12.3 $cd4.

User defined Formats: -


Created by using proc format.
(This topic covers in deeply in Proc Format)
Examples:-
Data fmt9a;
Infile datalines;
Input id name$ age sex$ sal dob time.;
Format dob time.;
Datalines;
001 David 23 m 50000 10:30:15
002 Amelia 32 f 25000 11:23:23
003 Alan 31 f 30000 08:34:45
004 Ravi 21 m 45000 12:43:56
005 Jim 35 f 28000 03:35:12
;
Run;
Proc format;
Value $gen 'f'='Female' 'm'='Male';
Run;
Applying Format in Dataset
Data fmt9b;
Set fmt9a;
Format sex $gen.;
Run;
Applying Format in Report
Proc report data=fmt9a nowd;
Column id name age sex sal dob ;
Define Sex/display format=$gen.;
Run;
91

Applying Format in Report with styles


Proc format;
Page

Value $col 'f'='RED' 'm'='GREEN';


Run;
Proc sort data=fmt9a;
By sex;
Run;
Proc print data=fmt9a NOOBS;
VAR id name age sal dob sex/style=[background=$col.] ;
Id sex;
By sex;
__________________________________________________________________________________________
STANSYS SOFTWARE SOLUTIONS
#7-1-621/113(67/3RT), Beside: Nagarjuna High School, Near: S.R.Nagar Community Hall,
S.R.Nagar, Hyd-38|Ph:9542195422/7671076710|www.stansys.co.in|[email protected]
Sumby sex;
Sum sal;
RUN;

Note: we can specify attributes as individually with above statements like Length, Label, Informat
and Format or all attributes we can specify with one statement that is Attrib Statement.

ATTRIB STATEMENT
Associates a format, informat, label, and/or length with one or more variables
Syntax: - ATTRIB variable-list(s) attribute-list(s) ;
Generally using Attrib statement we can change length, format, informat and label.
Data DS1;
Attrib name length=$10.;
Input id name$ sex$ age sal ;
Datalines;
001 Ronald m 23 50000
002 Clark f 22 34500
003 Roopa f 26 45000
;
Run;
Data DS2;
Attrib name length=$10. label='Emp Name';
Input id name$ sex$ age sal;
Datalines;
001 Ronald m 23 50000
002 Clark f 22 34500
003 Roopa f 26 45000
;
Run;
Data DS3;
Attrib name length=$10. label='Emp name'
sal format=comma6. label='Income';
Input id name$ sex$ age sal;
Datalines;
001 Ronald m 23 50000
002 Clark f 22 34500
003 Roopa f 26 4500
92

;
Run;
Page

Data DS4;
Attrib name length=$10.
doj format=worddate30. Label='Date of joining'
sex label='gender' sal format=dollar7. ;
Input id name$ sex$ age sal doj date9.;
Datalines;
001 Ronald m 23 50000 02Jan2009
002 Clark f 22 34500 22Feb2010
003 Roopa f 26 45000 30Apr2010
;
__________________________________________________________________________________________
STANSYS SOFTWARE SOLUTIONS
#7-1-621/113(67/3RT), Beside: Nagarjuna High School, Near: S.R.Nagar Community Hall,
S.R.Nagar, Hyd-38|Ph:9542195422/7671076710|www.stansys.co.in|[email protected]
Run;
Data DS5;
Attrib name length=$10.
dob informat=date9. format=ddmmyy8.
Label='Date of Birth'
doj informat=anydtdte9. format=ddmmyy10. Label='Date of Joining'
sex label='gender'
sal format=dollar7. ;
Infile datalines;
Input id name$ sex$ age sal dob doj ;
Datalines;
001 Ronald m 23 50000 11Mar1986 02Jan2009
002 Clark f 22 34500 30Dec1986 22Feb2010
003 Roopa f 26 45000 06Aug1987 30Apr2010
;
Run;
Data DS6;
Infile datalines;
Input id name$ sex$ age sal dob doj ;
Attrib name label='Empname'
dob informat=date9. format=ddmmyy8. Label='Date of Birth'
doj informat=anydtdte9. format=ddmmyy10. Label='Date of Joining'
sex label='gender'
sal format=dollar7. ;
Datalines;
001 Ronald m 23 50000 11Mar1986 02Jan2009
002 Clark f 22 34500 30Dec1986 22Feb2010
003 Roopa f 26 45000 06Aug1987 30Apr2010
;
Run;
Data DS7;
Infile datalines;
Input id name$ sex$ age sal dob date9. doj:date9. ;
Datalines;
001 Ronald m 23 50000 11Mar1986 02Jan2009
002 Clark f 22 34500 30Dec1986 22Feb2010
003 Roopa f 26 45000 06Aug1987 30Apr2010
;
93

Run;
Page

Data DS7a;
Attrib name length=$10.
dob informat=date9. format=ddmmyy8. Label='Date of Birth'
doj informat=anydtdte9. format=ddmmyy10. Label='Date of Joining'
sex label='gender'
sal format=dollar7. ;
Set DS6;
Run;
Note: When we specify length as an attribute with Attrib statement, Attrib statement
must write before Input or before Set statement otherwise when input statement or set
__________________________________________________________________________________________
STANSYS SOFTWARE SOLUTIONS
#7-1-621/113(67/3RT), Beside: Nagarjuna High School, Near: S.R.Nagar Community Hall,
S.R.Nagar, Hyd-38|Ph:9542195422/7671076710|www.stansys.co.in|[email protected]
statement executes whatever the length is there for variable
that will come into output.

And the output dataset variable order also change accordingly attrib statement variables
order that we can change again into required order in Proc print
But if we specify Attrib statement after Input or Set statement dataset order is Input
statement order (we can specify like this when we are not using Length in attrib
statement).

Interview Questions
Q1) What is INFORMAT? Syntax?
Q2) What is FORMAT? Syntax?
Q3) Write any three Informats & Formats with examples?
Q4) What is user defined formats? How can you create it?
Q5) Difference between Informats & Formats?
Q6) Explain about character Informats and Formats?
Q7) What is difference between $w. and $charw. ?
Q6) Write about below numeric informats & Formats? Write examples?
a) Commaw.d
b) Dollarw.d
c) Percentw.d
d) Bestw.d
Q7) Write about below Date informats & Formats values with current system date?
a) Date7.
b) Date9.
c) Ddmmyy8.
d) Ddmmyy10.
e) Anydtdte.
f) Datetime.
g) Time.
h) Datetime20.
i) Worddate20.
j) Weekdate30.
k) Yymmddn8.
94

l) Yymmddc8.
m) Yymmddd8.
Page

n) Yymmdds8.
o) Yymmddd10.
p) Yymmddc10.
q) Yymmdds10.
r) Mmddyys10.
s) Mmddyys10.
t) Mmddyyc10.
Q8) How dates work in SAS?
Q9) I have a variable called DOB and the values are in Date7 format.
__________________________________________________________________________________________
STANSYS SOFTWARE SOLUTIONS
#7-1-621/113(67/3RT), Beside: Nagarjuna High School, Near: S.R.Nagar Community Hall,
S.R.Nagar, Hyd-38|Ph:9542195422/7671076710|www.stansys.co.in|[email protected]
Iam reading that value into SAS without specifying any
informat so what is the
output? If i use with informat what is the output?
Q10) I have a variable called DOB and the values are in
Datetime.
Iam reading that value into SAS without specifying any informat so what is the
output? If i use with informat what is the output?
Q11) I have a variable called BIRTHTIME and the values are in time8.
Iam reading that value into SAS without specifying any informat so what is the
output? If i use with informat what is the output?
Q12) While reading data when i use informats for DATE Variables, values are coming as
a numbers but i want as dates what should i do?
Q13) I have a DATE Value 10Feb1959 I am reading that data into SAS using informat,
What is the value in output dataset?

Q14) I have a DATE Value 10Feb2012 I am reading that data into SAS using informat,
What is the value in output dataset?

Q15) Data is available in the location of "E:\SAS\RAW_DATA\IQ\INFORMATS &


FORMATS" Tasks are available at TASK notepad in above same location?
read that data into SAS and write the program for each task?

Q16) What is the purpose of Label statement?


Q17) What is Syntax of Label statement?
Q18) What is the difference between Rename option and Label statement?
Q19) what is the difference between label statement and Label option?
Q20) What is the difference between statement and option?
Q21) What is the significance of
LABEL NAME=’Emp Name’;
LABEL NAME=’ ‘;

Q22) Data is available in the location of "E:\SAS\RAW_DATA\IQ\LABEL"


Tasks are available at TASK notepad in above same location? Read that data into
SAS and write the program for each task ?

Q23) What is Length Statement?


95

Q24) What is Syntax of Length statement?


Q25) Why should I write length statement before Input statement? Why not after
Page

Input statement?
Q26) Data is available in the location of "E:\SAS\RAW_DATA\IQ\LENGTH"
Tasks are available at TASK notepad in above same location? Read that data into
SAS and write the program for each task ?

Q27) What is Attrib Statement?


Q28) What is Syntax of Attrib Statement?
Q29) Write the name of variable attributes?
Q30) How we can see the all of variables attributes in a dataset?

__________________________________________________________________________________________
STANSYS SOFTWARE SOLUTIONS
#7-1-621/113(67/3RT), Beside: Nagarjuna High School, Near: S.R.Nagar Community Hall,
S.R.Nagar, Hyd-38|Ph:9542195422/7671076710|www.stansys.co.in|[email protected]
Q31) Data is available in the location of
"E:\SAS\RAW_DATA\IQ\ATTRIB"
Tasks are available at TASK notepad in above same
location? Read that data into
SAS and write the program for each task ?

96
Page

__________________________________________________________________________________________
STANSYS SOFTWARE SOLUTIONS
#7-1-621/113(67/3RT), Beside: Nagarjuna High School, Near: S.R.Nagar Community Hall,
S.R.Nagar, Hyd-38|Ph:9542195422/7671076710|www.stansys.co.in|[email protected]
97
Page

__________________________________________________________________________________________
STANSYS SOFTWARE SOLUTIONS
#7-1-621/113(67/3RT), Beside: Nagarjuna High School, Near: S.R.Nagar Community Hall,
S.R.Nagar, Hyd-38|Ph:9542195422/7671076710|www.stansys.co.in|[email protected]

You might also like