The script begins by creating a temporary dataset named 'test1' with a single variable 'x' containing the string 'pradeep*'. Next, a second DATA step creates the 'test2' dataset from 'test1'. In this step, a new variable 'y' is generated by extracting the first two characters of the 'x' variable using the SUBSTR function. Finally, the PROC PRINT procedure is used to display the content of the 'test2' dataset, thus showing the result of the substring operation.
Data Analysis
Type : CREATION_INTERNE
The data used ('pradeep*') is defined directly in the SAS script via a DATALINES statement. There is no dependency on external datasets or the SASHELP library.
1 Code Block
DATA STEP Data
Explanation : This DATA STEP block creates a temporary dataset named 'test1'. It defines a character variable 'x' and uses the DATALINES statement to populate the dataset with the value 'pradeep*'. This step is essential to provide the base data for subsequent transformations.
Copied!
data test1;
input x $;
datalines;
pradeep*
;
1
DATA test1;
2
INPUT x $;
3
DATALINES;
4
pradeep*
5
;
2 Code Block
DATA STEP Data
Explanation : This second DATA STEP block creates a new dataset 'test2'. It reads observations from the 'test1' dataset (previously created) and applies the SUBSTR function to the 'x' variable. The SUBSTR(x,1,2) function extracts a substring from 'x' starting at the first position with a length of 2 characters, storing the result in the new variable 'y'.
Copied!
data test2;
set test1;
y=substr(x,1,2);
1
DATA test2;
2
SET test1;
3
y=substr(x,1,2);
4
3 Code Block
PROC PRINT
Explanation : This block uses the PROC PRINT procedure to display the content of the 'test2' dataset. This allows visualizing the data after the substring operation and verifying the result of the 'y' variable creation. The 'run;' statement executes the procedure, and 'quit;' terminates active procedures and releases associated resources.
Copied!
proc print data=test2;
run;
quit;
1
PROC PRINTDATA=test2;
2
3
RUN;
4
QUIT;
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.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.