Help using Base SAS procedures

Data _null_

Accepted Solution Solved
Reply
Contributor
Posts: 57
Accepted Solution

Data _null_

Hi,

I am using the code:

data Data;

infile datalines;

input name $ age;

datalines;

Sid 14

Alice 13

Barbara 13

Carol 13

Aalfred 13

;

run;

data _null_;

set Data;

file 'C:\Documents and Settings\Desktop\Input\test.txt';

put name $15 @5 age 2.;

run;

The output is:

    14        S

    13        A

    13        B

    13        C

    13        A

I do not understand how - put statement with @ in the above data _null_works?

Please advise

SK


Accepted Solutions
Solution
‎08-14-2013 04:37 PM
Super Contributor
Posts: 307

Re: Data _null_

Sorry ballardw, your post wasn't there when I hit submit. Your solution also works.

View solution in original post


All Replies
Super User
Posts: 11,343

Re: Data _null_

Posted in reply to Siddharth123

In a Put statement think of @ as "at", in you example it is writing the value of Age starting "at" column 5, which is overwriting name. You may want to be using "+5 Age" to write age starting at 5 columns past the end of the previous variable.

Contributor
Posts: 57

Re: Data _null_

Thank you. But I am still unsure why name doesnt start from the first column and I would expect that all the all values for name should occupy 1-4 columns and from 5th column the code would read age.

Regards

SK

Solution
‎08-14-2013 04:37 PM
Super Contributor
Posts: 307

Re: Data _null_

Sorry ballardw, your post wasn't there when I hit submit. Your solution also works.

Super Contributor
Posts: 307

Re: Data _null_

Posted in reply to Siddharth123

The "@" symbol in this context is a column pointer control. You've instructed SAS to write the AGE variable at column 5 -- which just so happens to overlap with the values in the NAME variable.

Try this instead.

data _null_;

set Data;

file ''C:\Documents and Settings\Desktop\Input\test.txt';

put name @20 age 2.;

run;

Super User
Posts: 5,509

Re: Data _null_

Posted in reply to Siddharth123

There is another defect in your program ... the instructions for writing NAME.  The instruction $15 says to write it in column 15.  If you meant to say it should occupy 15 characters, there should be a dot   $15.   added to the instructions.

🔒 This topic is solved and locked.

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

Discussion stats
  • 5 replies
  • 336 views
  • 8 likes
  • 4 in conversation