what is the difference between x=substr(name,1,2);
and substr(name,1,2)='x';

Answers were Sorted based on User's Feedback



what is the difference between x=substr(name,1,2); and substr(name,1,2)='x';..

Answer / sattwik panda

x=substr(name,1,2) will return first two character of a string whereas substr(name,1,2)='x' will replace first two character by 'x'.
Please try using the code below to get an idea.
data test;
name="Sattwik";
x=substr(name,1,2);
substr(name,1,2)='x';
run;

x will have the first two characters of name:'Sa'.
substr(name,1,2)='x' will replace first two characters of "Sattwik". So, now the name will contain "xttwik".

Is This Answer Correct ?    46 Yes 2 No

what is the difference between x=substr(name,1,2); and substr(name,1,2)='x';..

Answer / pratik

I agree with the first answer just a change is .it will be
"x ttwik" rather than "xttwik" as the replacement happens from the first loacation not as a whole.

Is This Answer Correct ?    14 Yes 0 No

what is the difference between x=substr(name,1,2); and substr(name,1,2)='x';..

Answer / oanhntt

x=substr(name,1,2) means you assign x value equal to the
first 2 characters of variable "name" while
substr(name,1,2)='x' just compare these fist 2 characters to
value 'x', so this seem useless without condition syntax
(correct one should be: if substr(name,1,2)='x' then /*do
some thing*/;).

Is This Answer Correct ?    4 Yes 16 No

Post New Answer

More SAS Interview Questions

In ARRAY processing, what does the DIM function do?

0 Answers  


if the Id has more then two transcatiion then show the first observation, IF Id has only two observation then It show both the observation

0 Answers   CTS,


explain the function of substr in sas? : Sas-administrator

0 Answers  


how do you want missing values handled? : Sas programming

0 Answers  


Code a PROC MEANS that shows both summed and averaged output of the data.

5 Answers  






1.What is the difference between _NULL_ , _ALL_, and _N_? 2.What are the uses of _NULL_ using in Data Steps? Can we _NULL_ in Proc Steps also? 3.How do call the macro variable in Data Steps? 4.How to construct Pivot tables in Excel Using SAS?

3 Answers  


how can u extract,transform and loading?

2 Answers   CitiGroup,


Explain the message 'Merge has one or more datasets with repeats of by variables'.

5 Answers  


what is program data vector? : Sas-administrator

0 Answers  


What is the difference between verification and validation?

9 Answers   Oracle,


What are the statements in proc sql?

0 Answers  


do you need to know if there are any missing values? : Sas programming

0 Answers  


Categories