The following SAS program is submitted:
data work.accounting;
set work.dept1 work.dept2;
run;
A character variable named JOBCODE is contained in both the WORK.DEPT1 and WORK.DEPT2 SAS data sets. The variable
JOBCODE has a length of 5 in the WORK.DEPT1 data set and a length of 7 in the WORK.DEPT2 data set.
Which one of the following is the length of the variable JOBCODE in the output data set?
A. 5
B. 7
C. 8
D. 12
Click Comment link to get answer
This comment has been removed by the author.
ReplyDelete'A'.
ReplyDeleteThe "set statement" takes the length of the common variable, as the length of that variable in the first dataset of set statement.
B is correct- If the data sets contain variables that have the same names, the values that are read in from the last data set overwrite the values that were read in from earlier data sets.
ReplyDeleteAnd that SAS is called ValSAS ? :-)
DeleteA
ReplyDeleteFurther clarification please
ReplyDeleteAnswer is A for sure.
ReplyDeleteA for sure
ReplyDeleteAnswer is A.
ReplyDeleteThe length of a variable always define automatically in the first statement and remain unchanged during the whole program until and unless we redefine it.
So when DEPT1 is set the lenght will set to 5 and remail unchanged during the data step.
This comment has been removed by the author.
DeleteB
ReplyDeletecorrect answer is A
ReplyDeleteCorrect Answer is A.
ReplyDeletereason is length of the first placed dataset's variable's length will be taken, not the second placed.
If set work.dept2 work.dept1;
then the answer is 7.
C is correct.i juss run the program...
ReplyDeletedata x;
input jobcode:5.;
datalines;
12345
123
1098
1234
;
run;
data y;
input name$ jobcode:7.;
datalines;
aaa 102
bbb 1234567
;
run;
data new;
set x y;
run;
proc contents data=new;
run;
sorry..the above ans is correct only when JOBCODE is numeric var.
ReplyDeleteAnswer is A.
ReplyDeleteHere is from SAS log:
WARNING: Multiple lengths were specified for the variable jobcode by input data set(s). This may cause truncation of data.
souji u r wrong it should be character variable . u have put numeric one which will be 8 by default so ans is 5
ReplyDeleteAnswer is A
ReplyDeletedata x;
length jobcode 5;
input jobcode:5.;
datalines;
12345
123
1098
1234
;
run;
data y;
length jobcode 7;
input name$ jobcode:7.;
datalines;
aaa 102
bbb 1234567
;
run;
data new;
set x y;
run;
proc contents data=new;
run;
SASCERT, could you clarify please?
ReplyDeleteA.... the length of a char var is fixed in work dataset1 and it takes same length while copying new value into it ....for example
ReplyDeletedata try;
a='asdfg';
a='abcdefg';
put @5 a;
run;
in log window we will find a value as abcde only 5 chars ...
the char var takes first defined val length
while numeric var by default it will take 12
@ ani ...... u r right
ReplyDeleteI tried it an get answer A
ReplyDeletedata one;
ReplyDeleteinput jobcode $5. dept $3.;
datalines;
11111abc
22222def
33333xyz
;
run;
data two;
input jobcode $7. dept $3.;
datalines;
1111117abc
2222227def
3333337xyz
;
run;
data three;
set one two;
run;
proc print data=three;run;
proc contents data=three;run;
O/p:
Obs jobcode dept
1 11111 abc
2 22222 def
3 33333 xyz
4 11111 abc
5 22222 def
6 33333 xyz
contents:
Alphabetic List of Variables and Attributes
# Variable Type Len
2 dept Char 3
1 jobcode Char 5
The answer is a and here is the correct version of Saujis program
ReplyDeletedata x;
input jobcode$5.;
datalines;
12345
123
1098
1234
;
run;
data y;
input name$ jobcode$7.;
datalines;
aaa 102
bbb 1234567
;
run;
data new;
set x y;
run;
proc contents data=new;
run;
The answer is C. Ran the program and it states the length is 8.
ReplyDeletedata cc1;
input job_code $;
put @5 job_code;
datalines;
abcde
;
run;
data cc2;
input job_code $;
put @7 job_code;
datalines;
yuiophj
;
run;
data cc3;
set cc1 cc2;
run;
proc contents data=cc3;
run;
Output:
# Variable Type Len
1 job_code Char 8
Sorry I realized I did this incorrectly. The answer is not C but should be A.
DeleteAns is def A . If we do not specify length, then it be 8. there is no case of overwriting here since it is not interleaving (as there is no by statement) but concatenation only.
ReplyDeletehere is the corrected program.
ReplyDeletesince it is specified that jobcode is the numeric variable.
data x;
input jobcode $5.;
datalines;
aaaaa
;
run;
data y;
input jobcode$7. ;
datalines;
sdssfdf
;
run;
data new;
set x y;
run;
proc contents data=new;
run;
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteA if jobcode is character variable.
ReplyDeletewhat if its like set work.dept1 set work.dept2;
ReplyDeletedefinitely A
ReplyDeleteAnswer : A
ReplyDeleteRules for Length Conflict Resolution in SAS
a) When the length is explicitly defined in either of the dataset despite the position use that (not this scenario in Question)
b) If Length is explicitly defined in both the datasets , then consider position. Length of first Dataset overrides others.
correct answer is A
ReplyDeleteA
ReplyDeleteI simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.accounting and bookkeeping companie
ReplyDeleteNice Blog, Thanks for sharing
ReplyDeleteTeam auditing company in uae and aroma oil
Interesting article. We are a leading audit firm in Dubai, UAE.
ReplyDeleteAre you looking for experts to help you obtain the general trading license in Dubai? then we are always ready to help you out. Get license to do business in UAE. 100% Legal assistance.
ReplyDeleteaccounting firm in dubai
ReplyDeleteBest Ayurvedic Clinic In Dubai
ReplyDeleteCompany formation in SRTIP Free zone, the Sharjah Research, Technology and Innovation Park, offers a compelling opportunity for businesses. With a streamlined process and dedicated authorities, entrepreneurs can establish their companies efficiently. SRTIP Freezone provides a supportive ecosystem for research, technology, and innovation-driven enterprises, fostering collaboration with academia and government entities. Benefits include 100% foreign ownership, tax exemptions, state-of-the-art infrastructure, access to funding and venture capital, and a dynamic network of like-minded businesses. SRTIP Free zone supports diverse sectors such as technology, advanced manufacturing, renewable energy, and health sciences. Comprehensive support services, including legal assistance and visa facilitation, ensure a smooth setup. With its strategic location and incentives, SRTIP Free zone is an attractive choice for entrepreneurs looking to tap into the UAE's innovation ecosystem.
ReplyDeleteNice blog post. I really enjoyed reading. Thanks for sharing. Keep posting.
ReplyDelete