BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Siddharth123
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
Fugue
Quartz | Level 8

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

View solution in original post

5 REPLIES 5
ballardw
Super User

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.

Siddharth123
Obsidian | Level 7

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

Fugue
Quartz | Level 8

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

Fugue
Quartz | Level 8

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;

Astounding
PROC Star

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 1248 views
  • 8 likes
  • 4 in conversation