BookmarkSubscribeRSS Feed
garag
Calcite | Level 5


Hi,

I have the following need.

I have a varible XXX and I would save the value of this variable in an external file. If I do something like this:

data _null_;

   file 'outup.txt';

   put XXX;

run;

The file is empty and if I do this

data _null_;

   file 'outup.txt';

   put &XXX;

run;

I get an error. Do there is a way to save the value of a variable in a file?

Many thanks

2 REPLIES 2
PGStats
Opal | Level 21

If variable XXX comes from a dataset, you should refer to it (i.e. SET MYDATASET; ) . If it is a macro variable, you should assign it to a variable (i.e. XXX="&XXX"; put XXX; ) or use quotes in the put statement (i.e. put "&XXX"; )

PG

PG
Cynthia_sas
SAS Super FREQ

Hi: As PG has explained, you must point to a SAS dataset in order to use a variable name in a PUT statement (unless you are creating the variable in your program).

The program below writes the NAME variable from SASHELP.CLASS to a flat file for only the students with an AGE that is GE 15.

cynthia

data _null_;

  set sashelp.class;

  where age ge 15;

  file 'c:\temp\myflatfile.txt';

  put name;

run;

Then if you open MYFLATFILE.TXT with Notepad, you will see the 5 students with ages greater than or equal to 15 in SASHELP.CLASS:

Janet

Mary

Ronald

William

Philip

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 1119 views
  • 0 likes
  • 3 in conversation