SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Need to know the Logic of SAS processing for this program.

Accepted Solution Solved
Reply
Contributor ved
Contributor
Posts: 27
Accepted Solution

Need to know the Logic of SAS processing for this program.

Hello,

I am preparing for Base SAS Certification , and need to know basic logic behind the following below question.

Given the text file COLORS.TXT:

----+----1----+----2----+----

RED    ORANGE  YELLOW  GREEN

BLUE  INDIGO  PURPLE  VIOLET

CYAN  WHITE  FUCSIA  BLACK

GRAY  BROWN  PINK    MAGENTA


The following SAS program is submitted:

data WORK.COLORS;

      infile 'COLORS.TXT';

      input @1 Var1 $ @8 Var2 $ @;

      input @1 Var3 $ @8 Var4 $ @;

run;

What is the output of the program and why. kindly give the logic behind the program output.

Many thanks in advance

regards

Ved


Accepted Solutions
Solution
‎04-23-2015 03:03 PM
PROC Star
Posts: 7,474

Re: Need to know the Logic of SAS processing for this program.

Yes, but in an earlier response you said " is that means in above code @ prevents second input statement to being read and results in repeatition of values of var1 and var2 for var3 and var4 ??".

My answer is no! Think about the two input statements.

     input @1 Var1 $ @8 Var2 $ @;

@1 will read Var1 from col1, then @8 will move the pointer to col8 and input Var2. Finally, the @ will cause the pointer to not move to the next record until either the next instruction or the next iteration of the data step

Then:

     input @1 Var3 $ @8 Var4 $ @;

will move the pointer back to col1 and read Var3, then the @8 will cause the pointer to input Var4 from col8. Finally, the @ will cause the pointer to not move to the next record until either the next instruction or the next iteration of the data step. There aren't any more instructions, thus it is irrelevant as the program will then move to the next iteration.

View solution in original post


All Replies
Super User
Posts: 11,343

Re: Need to know the Logic of SAS processing for this program.

Did you try running the program and looking at the output?

The key is the last @ in the first input. Look at the documentation for INPUT.

Contributor ved
Contributor
Posts: 27

Re: Need to know the Logic of SAS processing for this program.

Yes, i have runned the code and result it showing me the repeatition of the values of var1 and var2 for var3 and var4 respectively.As per 9.2 documentation @ : (trailing @) prevents SAS from automatically reading a new data record into the input buffer when a new INPUT statement is executed within the same iteration of the DATA step.

is that means in above code @ prevents second input statement to being read and results in repeatition of values of var1 and var2 for var3 and var4 ??

Please correct if i am wrong.

thanks in advance.

rgds

ved

PROC Star
Posts: 7,474

Re: Need to know the Logic of SAS processing for this program.

You're wrong, other than your explanation of the trailing blank. Provide a different explanation of your code. Would help if you explain what the @1 does.

Contributor ved
Contributor
Posts: 27

Re: Need to know the Logic of SAS processing for this program.

I think the first @ trailing in input statment hold the pointer and prevent reading the next input statement.

PROC Star
Posts: 7,474

Re: Need to know the Logic of SAS processing for this program.

I don't disagree with your explanation of the first trailing @. I was suggesting that you explain what the @1 and @8 do, and why the second trailing @ is irrelevant.

Contributor ved
Contributor
Posts: 27

Re: Need to know the Logic of SAS processing for this program.

i think @1 guide the pointer to read the first record(RED) for first variable i.e, Var1 and similarly @8 guide pointer to read second record(ORANGE )  for Var2.

Solution
‎04-23-2015 03:03 PM
PROC Star
Posts: 7,474

Re: Need to know the Logic of SAS processing for this program.

Yes, but in an earlier response you said " is that means in above code @ prevents second input statement to being read and results in repeatition of values of var1 and var2 for var3 and var4 ??".

My answer is no! Think about the two input statements.

     input @1 Var1 $ @8 Var2 $ @;

@1 will read Var1 from col1, then @8 will move the pointer to col8 and input Var2. Finally, the @ will cause the pointer to not move to the next record until either the next instruction or the next iteration of the data step

Then:

     input @1 Var3 $ @8 Var4 $ @;

will move the pointer back to col1 and read Var3, then the @8 will cause the pointer to input Var4 from col8. Finally, the @ will cause the pointer to not move to the next record until either the next instruction or the next iteration of the data step. There aren't any more instructions, thus it is irrelevant as the program will then move to the next iteration.

Contributor ved
Contributor
Posts: 27

Re: Need to know the Logic of SAS processing for this program.

I am sorry for the inconvience . I think i missinterpret your earlier suggestion, as i was talking about trailing(@) and ignored the explaination of @1 point.

Thanks for the correction and help me to understand the whole processing of the code. Your explaination helped me alot.

regards

Ved

PROC Star
Posts: 7,474

Re: Need to know the Logic of SAS processing for this program.

And a 2nd key is to look where the second input statement is pointing. The @, at the end of the second input statement is superfluous, but doesn't hurt anything.

But run the code and carefully compare the input file with the file that the data step creates.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 1609 views
  • 3 likes
  • 3 in conversation