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

How do you add a number to a macro variable?

2 Answers  


What function CATX syntax does?

0 Answers  


I use NOCUM/NOPERCENT option in the tables statement like this Proc freq data = deepak; tables x y /nocum nopercent; run; Here I get nopercent and nocum in the output only for variables x and y. How do i do it for all variables? Deepak

1 Answers  


Hi,by usining ptf how we have to combine (likr merge)10 datasets at a time in the oracle database(and write a macro code also)?Like this i have a douts a lot if you dont mind may please send one text mail for me(madhusudhanap16@gmail.com)?

0 Answers  


What is difference between rename and lable in sas?

10 Answers   Satyam,


i have a macro variable var1,var2. i want titles for the each macro variable separately? how it is possible?

1 Answers   L&T,


What is the purpose of using the N=PS option?

2 Answers   Oracle,


What is the purpose of the trailing @? The @@? How would you use them?

10 Answers   Accenture,


What is a macro routine?

0 Answers  


Differences between where and if statement?

0 Answers  


What does proc print, and proc contents are used for?

0 Answers  


Explain the purpose of substr functions in sas programming.

0 Answers  


Categories