BookmarkSubscribeRSS Feed
Karen_sas11
Calcite | Level 5

Hi guys,

I got an interview question recently was asked that in RETAIN statement, values is retain from a iteration to next next iteration, is it possible to be processed reversely?

I think the question is a trick, because Retain occurs in PDV, and it go through loops by loops.....

Is anyone can show me how to answer this question?

 

Many Thanks!

10 REPLIES 10
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

to best answer that question a good understanding of what Retain does would be helpful.  Please find at this link an explanation and examples of the retain statement.

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000214163.htm

 

Karen_sas11
Calcite | Level 5

Thanks for sharing the link.

Let's take an example;

data example;
input a b c;
retain total 0;
total=total+(a+b+c);
cards;
1 3 5
2 4 6
7 8 9
;
run;

 

can it process from the last iteration to the first iteration? I don't think it works

The question is testing if you understand how retain syntax works, and loops by loops in the PDV.

novinosrin
Tourmaline | Level 20

, is it possible to be processed reversely?

 

 do you mean

 

do i=nobs to 1 by -1;

set have point=i nobs=nobs;

whatever with a newvar that will mimic retain;

end;

 

A lot of interviewers have this crazy attitude to often think they know more than the candidate and play with unecessary questions in my humble opinion

Karen_sas11
Calcite | Level 5

Yes indeed. Sometimes they like playing games with you. In this question, I guess they are testing you if you understand the process in PDV, and if you know how RETAIN works. 

mkeintz
PROC Star

@novinosrin 

 

YourThis example does not quite prove the point regarding a RETAIN statement.   Even non-retained variables would not be re-initialized over DO loop iterations.

 

But your point is that RETAIN works over DATA STEP iterations, regardless of the order of observations read at each iteration. I.e.  retain works here:

 

data pointers;
  input ptr  @@;
datalines;
5 4 1 18 6
run;

data want;
  set pointers;
  retain  X 1001;
  set sashelp.class point=ptr;
run;

X retains the value 1001 in every observation in data set WANT.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
novinosrin
Tourmaline | Level 20

I agree and indeed your example is full proof with neat randomisation of order. Well covered

SASKiwi
PROC Star

IMO there are better ways of assessing a job candidate's SAS knowledge and experience than asking quiz questions...

 

So now you understand the RETAIN statement, but in the next interview they ask you about the LAG function that you've never used! You are still no better off trying to demonstrate your SAS knowledge.

 

One approach I've had success with as an interviewer, is to provide interviewees with a real SAS program related to the job they are applying for and ask them to provide feedback on it. It is the level and type of feedback they provide that is insightful of their SAS skills. This approach also enables interviewees to decide for themselves if they are capable of that level of programming. 

novinosrin
Tourmaline | Level 20

Great point.

 

I was disqualified in an interview for forgetting syntax of an option modifier-  in find function .

 

In my resume, I have/still mention/ed strong foundation components in SAS programming and that interviewer didn't seem to like that.  I was deemed not good and unfit for SAS programming role. Being disheartened, I told my parents about this, and parents were like next time if that happens invite that person for a competition offline to settle the score to feel better. I had a few pints at a local pub to forget that episode

SASKiwi
PROC Star

@novinosrin - If I had a similar experience, I would be asking myself is this the type of employer I would want to work for? If they are nit-picky in a job interview imagine what they would be like as a boss? Might be a case of thanks but no thanks from me! 

ballardw
Super User

@Karen_sas11 wrote:

Hi guys,

I got an interview question recently was asked that in RETAIN statement, values is retain from a iteration to next next iteration, is it possible to be processed reversely?

I think the question is a trick, because Retain occurs in PDV, and it go through loops by loops.....

Is anyone can show me how to answer this question?

 

Many Thanks!


My initial response would have been to ask the questioner what the input and desired result were. "Reversely" could have a number of meanings, at least to me.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 1482 views
  • 4 likes
  • 6 in conversation