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

hi i date is 05sep2005; i want the oupput like 05sep2005:00:00:00 ; how it wil come?

6 Answers   Accenture,


For what purpose would you use the RETAIN statement?

0 Answers   Quintiles,


tell me about intnx, intcx functions?

4 Answers   CitiGroup,


data data1; input dt account; format dt date9.; cards; 1745 1230 1756 1120 1788 1130 1767 1240 ; data data2; input startdt enddt total; format startdt date9. enddt date9.; cards; 1657 1834 12300 1557 1758 16800 1789 1789 12300 1788 1345 12383 1899 1899 13250 ; proc sql; create table data3 as select * from data1 as x left join data2 as y on x.dt>=y.startdt and x.dt<=y.enddt; quit; Here, we are getting cartision product. But,I want left join report consisting of this program. It should not get duplicate values. you can modify the program also.

0 Answers  


how do u validate sas program

3 Answers   Accenture,






how to get second highest salary from a employee table and how get a 5th highest salary from a employee table?

11 Answers   ABC, Amex,


Where do you use proc means over proc freq?

0 Answers  


what is Business Intelligence?

3 Answers   CitiGroup,


How to sort in descending order?

0 Answers  


how to extract data from SAP servers? Is like oracle servers or any other methods to extract please reply me.

1 Answers  


For clinical entire study how many tables will create approx?

0 Answers   TCS,


what does the run statement do? : Sas programming

0 Answers  


Categories