banner



What Sas Statements Would You Code To Read An External Raw Data File To A Data Step?

Very Basic:·

What SAS statements would yous code to read an external raw data file to a Information step?
INFILE statement.

· How do you read in the variables that y'all need?
Using Input statement with the column pointers like @5/12-17 etc.

· Are you familiar with special input delimiters? How are they used?
DLM and DSD are the delimiters that I've used. They should be included in the infile statement. Comma separated values files or CSV files are a common type of file that can be used to read with the DSD option. DSD option treats two delimiters in a row as MISSING value.

DSD also ignores the delimiters enclosed in quotation marks.

· If reading a variable length file with fixed input, how would y'all preclude SAS from reading the next tape if the last variable didn't have a value?
By using the choice MISSOVER in the infile statement.If the input of some data lines are shorter than others and so we utilize TRUNCOVER option in the infile statement.

· What is the difference between an informat and a format? Name three informats or formats.

Informats read the data. Format is to write the information.
Informats: comma. dollar. date.
Formats can be same equally informatsInformats: MMDDYYw. DATEw. TIMEw. , PERCENTw,Formats: WORDIATE18., weekdatew.

· Name and draw iii SAS functions that you have used, if any?

LENGTH: returns the length of an statement non counting the trailing blanks.(missing values accept a length of
1)Ex:

a='my cat';
x=LENGTH(a);

Result: ten=6…

SUBSTR: SUBSTR(arg,position,northward) extracts a substring from an argument starting at 'position' for 'north' characters or until end if no 'due north'.
Ex:

data dsn;
A='(916)734-6241';
10=SUBSTR(a,2,3);
RESULT: x='916' ;
run;
TRIM: removes trailing blanks from graphic symbol expression.
Ex: a='my '; b='cat';10= TRIM(a)(b); Consequence: x='mycat'.

SUM: sum of non missing values.Ex: x=Sum(three,5,1); result: x=9.0

INT: Returns the integer portion of the argument.

· How would y'all code the criteria to restrict the output to be produced?
Use NOPRINT selection.

· What is the purpose of the trailing @ and the @@? How would you employ them?
@ holds the value past the data step.@@ holds the value till a input statement or end of the line.

Double trailing @@: When you lot have multiple observations per line of raw data, we should use double trailing signs (@@) at the end of the INPUT argument. The line hold specifies like a stop sign telling SAS, "finish, hold that line of raw information".
ex:
data dsn;

input sex $ days;
cards;
F 53
F 56
F 60
F 60
F 78
F 87
F 102
F 117
F 134
F 160
F 277
M 46
M 52
M 58
M 59
Chiliad 77
M 78
Thou lxxx
M 81
M 84
M 103
M 114
M 115
Yard 133
M 134
M 175
M 175
;
run;

The above plan can be changed to make the programme shorter using @@ ....

data dsn;
input sex activity $ days @@;
cards;
F 53 F 56 F 60 F 60 F 78 F 87 F 102 F 117 F 134 F 160 F 277M 46 Yard 52 M 58 M 59 M 77 G 78 1000 80 M 81 M 84 M 103 M 114M 115 G 133 M 134 M 175 One thousand 175
;
run;

Trailing @: Past using @ without specifying a column, it is as if you are telling SAS," stay tuned for more information. Don't bear upon that dial". SAS will hold the line of data until information technology reaches either the end of the data step or an INPUT statement that does not terminate with the abaft.

· Under what circumstances would you code a SELECT construct instead of IF statements?
When you have a long serial of mutually exclusive conditions and the comparing is numeric, using a SELECT group is slightly more efficient than using IF-Then or IF-And so-ELSE statements because CPU fourth dimension is reduced.

SELECT Group:
Select: begins with select group.When: identifies SAS statements that are executed when a particular condition is true.
Otherwise (optional): specifies a statement to be executed if no WHEN status is met.
Cease: ends a SELECT group.

·What statement yous code to tell SAS that it is to write to an external file?

.What argument practice you code to write the record to the file?
PUT and FILE statements.

· If reading an external file to produce an external file, what is the shortcut to write that record without coding every unmarried variable on the tape?

· If you're not wanting whatsoever SAS output from a data pace, how would y'all code the data argument to forestall SAS from producing a set?
Information _Null_

· What is the one statement to gear up the criteria of information that can be coded in whatever pace?
Options statement: This a part of SAS program and effects all steps that follow it.

· Take you ever linked SAS code? If so, describe the link and any required statements used to either process the lawmaking or the step itself

.· How would you include common or reuse code to exist processed along with your statements?
By using SAS Macros.

· When looking for data contained in a character string of 150 bytes, which function is the all-time to locate that data: scan, index, or indexc?

Browse.· If y'all have a data set that contains 100 variables, simply you need just five of those,

.what is the lawmaking to forcefulness SAS to use only those variable?
Using KEEP option or statement.

· Code a PROC SORT on a information set containing State, Commune and County as the master variables, along with several numeric variables.

Proc sort information=one;
BY State District County ;
Run ;

· How would y'all delete duplicate observations?
NONUPLICATES

· How would you lot delete observations with duplicate keys?
NODUPKEY

· How would you code a merge that will go along just the observations that take matches from both sets.
Cheque the condition past using If statement in the Merge statement while merging datasets.

· How would you code a merge that will write the matches of both to 1 data set, the non-matches from the left-well-nigh data.

Step1: Define iii datasets in DATA step
Step2: Assign values of IN statement to different variables for two datasets
Step3: Cheque for the condition using IF statement and output the matching to kickoff dataset and no matches to different datasets

Ex:

data xxx;
merge yyy(in = inxxx) zzz (in = inzzz);
by aaa;
if inxxx = 1 and inyyy = 1;
run;

· What is the Program Data Vector (PDV)? What are its functions?
Function: To shop the electric current obs;PDV (Program Data Vector) is a logical area in retention where SAS creates a dataset ane observation at a time. When SAS processes a data step it has 2 phases. Compilation phase and execution phase. During the compilation stage the input buffer is created to hold a record from external file. After input buffer is created the PDV is created. The PDV is the expanse of retention where SAS builds dataset, i ascertainment at a time. The PDV contains two automatic variables _N_ and _ERROR_.

The Logical Programme Data Vector (PDV) is a set of buffers that includes all variables referenced either explicitly or implicitly in the Information step. It is created at compile time, then used at execution time as the location where the working values of variables are stored every bit they are candy by the Data stride program(source: http://www2.sas.com/proceedings/sugi24/Posters/p235-24.pdf).

· Does SAS 'Interpret' (compile) or does it 'Interpret'? Explain.
SAS compiles the code· At compile time when a SAS information set is read, what items are created?Automatic variables are created. Input Buffer, PDV and Descriptor Information

· Name statements that are recognized at compile time only?
PUT

· Name statements that are execution merely.
INFILE, INPUT·

.Place statements whose placement in the Data stride is critical.
DATA, INPUT, RUN.

· Name statements that function at both compile and execution time.
INPUT

· In the menstruum of Data step processing, what is the showtime action in a typical Information Footstep?
The Information step begins with a Information statement. Each time the Information statement executes, a new iteration of the Data step begins, and the _N_ automatic variable is incremented past 1.

· What is _n_?
It is a Information counter variable in SAS.
Annotation: Both -N- and _ERROR_ variables are ever available to you in the data step

.–North- indicates the number of times SAS has looped through the data step.This is not necessarily equal to the ascertainment number, since a simple sub setting IF statement can change the human relationship between Observation number and the number of iterations of the information step.The –Fault- variable ha a value of ane if there is a mistake in the information for that observation and 0 if it is not. Ex: This is nothing but a implicit variable created by SAS during information processing. It gives the total number of records SAS has iterated in a dataset. It is Available but for data step and not for PROCS. Eg. If we desire to observe every third record in a Dataset thenwe can utilise the _n_ as follows

Data new-sas-data-set;
Fix erstwhile;
if modern(_n_,3)= 1 and so;
run;

Note: If nosotros utilise a where clause to subset the _n_ will not yield the required issue.

How practice i convert a numeric variable to a grapheme variable?
You must create a differently-named variable using the PUT office.

How do i catechumen a character variable to a numeric variable?
You must create a differently-named variable using the INPUT function.

How can I compute the age of something?
Given two sas date variables born and calc:

age = int(intck('month',born,calc) / 12);
if calendar month(born) = month(calc) then age = historic period - (day(born) > twenty-four hour period(calc));

How can I compute the number of months betwixt 2 dates?
Given two sas date variables begin and finish:

months = intck('month',begin,terminate) - (solar day(end) <>

How tin I determine the position of the nth word within a character string?

Employ a combination of the INDEXW and SCAN functions: pos = indexw(string,scan(cord,n));

I need to reorder characters within a string...apply SUBSTR?
Yous tin can do this using only one office call with Translate versus two functions calls with SUBSTR. The following lines each move the kickoff character of a 4-graphic symbol string to the terminal:


reorder = translate('2341',string,'1234');
reorder = substr(string,ii,3) substr(cord,i,1);
How can I put my sas date variable so that December 25, 1995 would appear equally '19951225'? (with no separator)

utilise a combination of the YEAR. and MMDDYY. formats to simply brandish the value:
put sasdate year4. sasdate mmddyy4.;

or use a combination of the PUT and COMPRESS functions to shop the value:
newvar = compress(put(sasdate,yymmdd10.),'/');

How can I put my sas time variable with a leading zero for hours 1-9?
Employ a combination of the Z. and MMSS. formats:
hrprint = hour(sastime);
put hrprint z2. ':' sastime mmss5.;

INFILE OPTIONS
Prepared by Sreeja E V(sreeja@kreara.com) source: kreara.blogspot.com.

Infile has a number of options available.

FLOWOVER

FLOWOVER is the default option on INFILE statement. Hither, when the INPUT statement reaches the end of not-blank characters without having filled all variables, a new line is read into the Input Buffer and INPUT attempts to make full the residuum of the variables starting from column 1. The next time an INPUT statement is executed, a new line is brought into the Input Buffer.
Consider the following text file containing three variables id, type and amount.

11101 A
11102 A 100
11103 B 43
11104 C
11105 C 67


The following SAS code uses the flowover pick which reads the adjacent not missing values for missing variables.

data B;
infile "External file" flowover;
input id $ blazon $ corporeality;
run ;

which creates the following dataset

MISSOVERWhen INPUT reads a brusk line, MISSOVER pick on INFILE statement does not allow it to move to the next line. MISSOVER choice sets all the variables without values to missing.

data B;
infile "External file" missover;
input id $ type $ amount;
run ;

which creates the following dataset

TRUNCOVER

Causes the INPUT statement to read variable-length records where some records are shorter than the INPUT statement expects. Variables which are not assigned values are set to missing.

Departure between TRUNCOVER and MISSOVER

Both volition assign missing values to variables if the data line ends before the variable's field starts. Just when the data line ends in the middle of a variable field, TRUNCOVER volition accept as much as is there, whereas MISSOVER will assign the variable a missing value.

Consider the text file below containing a character variable chr.
a
bb
ccc
dddd
eeeee
ffffff

Consider the post-obit SAS code

data trun;
infile "External file" truncover;
input chr $3. ;
run ;

When using truncover option we become the following dataset

data miss;
infile "External file" missover;
input chr $3. ;
run ;

While using missover option we get the output

SAS Proficiency Test past Judy Loren

Different Means to employ PUT Statement;

http://world wide web.cmg.org/measureit/problems/mit45/m_45_10.html

%include argument: which looks similar a macro but isn't really, sucks the contents of the simply-generated file into the input stream. The outcome will exist that the step will effectively contain all of the rename statements generated in the previous step, accomplishing the renaming of all columns. source:Vancouver_Fall2007/Tips_Tricks.pdf

What Sas Statements Would You Code To Read An External Raw Data File To A Data Step?,

Source: http://studysas.blogspot.com/2008/09/sas-interview-questionsbase-sas.html

Posted by: baxteralthe1967.blogspot.com

0 Response to "What Sas Statements Would You Code To Read An External Raw Data File To A Data Step?"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel