DATA ABC;
INPUT TDATE DATE9. AVG;
CARDS;
18APR2008 150.00
19APR2008 167.00
20APR2008 123.00
21APR2008 145.00
;
RUN

HOW CAN I FIND THE DIFFERENCE BETWEEN AVG OF 18APR2008 ANF
21APR2008??

IF ANY ONE GETS IT PLS TRY TO POST IT.

Answers were Sorted based on User's Feedback



DATA ABC; INPUT TDATE DATE9. AVG; CARDS; 18APR2008 150.00 19APR2008 167.00 20APR2008 123.00 21..

Answer / rajaanku11

The Above can be done in a single data step as
follows.Actually this is suggestable.


data _null_;
set abc;
retain z;
if tdate='18APR2008'D then
z=avg;
if tdate='21APR2008'D then
do;
diff=Z-avg;
put 'the difference=' diff;
stop;
end;
run;

Is This Answer Correct ?    5 Yes 1 No

DATA ABC; INPUT TDATE DATE9. AVG; CARDS; 18APR2008 150.00 19APR2008 167.00 20APR2008 123.00 21..

Answer / nagesh sriram

Hi,
I am think that the difference between the first and last
records value?

data _null_;
set abc end=last;
retain first;
if _n_=1 then first=avg;
if last=1 then do;
diff=first - avg;
put 'The difference is =' diff;
stop;
end;
run;

here _n_=1 is hold the first record in the abc dataset.
Last=1 means is hold the last record in the dataset.

Is This Answer Correct ?    2 Yes 0 No

DATA ABC; INPUT TDATE DATE9. AVG; CARDS; 18APR2008 150.00 19APR2008 167.00 20APR2008 123.00 21..

Answer / kumaraswamy maduri

If you want only for the above specified dates then answer
3 works and if it is for first and last observations in the
dataset then answer 4 works.

Is This Answer Correct ?    0 Yes 0 No

DATA ABC; INPUT TDATE DATE9. AVG; CARDS; 18APR2008 150.00 19APR2008 167.00 20APR2008 123.00 21..

Answer / rohitbedi

Shortest answer: Copy the dataset and create a new field using difn function on avg where n=3 as shown below.

data abc2;
set abc;
diff = dif3(avg);
run;

Is This Answer Correct ?    0 Yes 0 No

DATA ABC; INPUT TDATE DATE9. AVG; CARDS; 18APR2008 150.00 19APR2008 167.00 20APR2008 123.00 21..

Answer / rajaanku11

Hi, pls modify slight changes to the above prog.

data _null_ ;
set abc;
if tdate='18APR2008'D then
call symput('x',avg);
if tdate='21APR2008'D then
call symput('y',avg);
run;
%put _user_;
data _null_;
z=&x-&y;
put 'the difference=' z;
run;

Is This Answer Correct ?    2 Yes 3 No

DATA ABC; INPUT TDATE DATE9. AVG; CARDS; 18APR2008 150.00 19APR2008 167.00 20APR2008 123.00 21..

Answer / chandu

We can solve this with array......

Is This Answer Correct ?    0 Yes 1 No

DATA ABC; INPUT TDATE DATE9. AVG; CARDS; 18APR2008 150.00 19APR2008 167.00 20APR2008 123.00 21..

Answer / abhilash

Use symgetfunction to resolve a macro variable with in same
data step while creating macro variable using call symput.


DATA test;
SET ABC;
IF TDATE='18APR2008'D THEN
CALL SYMPUT('A2',AVG);
ELSE IF TDATE='21APR2008'D THEN
CALL SYMPUT('B2',AVG);
diff = symget('a2') - symget('b2');
RUN;

Is This Answer Correct ?    1 Yes 2 No

DATA ABC; INPUT TDATE DATE9. AVG; CARDS; 18APR2008 150.00 19APR2008 167.00 20APR2008 123.00 21..

Answer / rajaanku11

DATA ABC;
INPUT TDATE DATE9. AVG;
CARDS;
18APR2008 150.00
19APR2008 167.00
20APR2008 123.00
21APR2008 145.00
;
RUN;

data _null_;
set abc;
if tdate='18APR2008'D then
call symput('x',avg);
if tdate='21APR2008'D then
call symput('y',avg);
z=&x-&y;
run;

data _null_;
z=&x-&y;
put 'the difference='z;
run;

Is This Answer Correct ?    2 Yes 4 No

Post New Answer

More SAS Interview Questions

what are the methods that you would employ to fine tune your SQL extract process using SAS/Access or Proc SQL?

1 Answers  


What are the data types does SAS contain?

0 Answers  


Differentiate between sas functions and sas procedures.

0 Answers  


Mention the difference between ceil and floor functions in sas?

0 Answers  


what is the use of proc sql?

5 Answers   CitiGroup,






What is program data vector (pdv)?

0 Answers  


i want for interview question & answer plz it need immediate send t my mail raviprakashmot@gmal.cm

0 Answers   SAS,


how can you import .csv file in to sas? : Sas programming

0 Answers  


Which is the Best SAS training Institute in Delhi NCR for SAS certification preparation

1 Answers   SAS,


Explain the main difference between the sas procedures and functions? : Sas-administrator

0 Answers  


If reading an external file to produce an external file, what is the shortcut to write that record without coding every single variable on the record?

4 Answers  


There is a field containing a date. It needs to be displayed in the format "ddmonyy" if it's before 1975, "dd mon ccyy" if it's after 1985, and as 'Disco Years' if it's between 1975 and 1985. How would you accomplish this in data step code? Using only PROC FORMAT

8 Answers   D&B,


Categories