BookmarkSubscribeRSS Feed
emaguin
Quartz | Level 8

In spss i can do this

print / id x1 to x5 y3 to y8 (a4,5f6.2,/,4x,5f6.3).

which gives

1234 23.22 34.66 18.56 99.01 24.33

      3.44 87.33  8.22  4.55  6.22

this would go to the output window but i could also send it to a file, both would be utf-8 text, not html.

the write command can do the same but only to a file as utf-8 text.

In proc print i say proc print data=xx; var id x1-x5 y3-y8; but what i get is one row per record.

Is it possible, somehow, in sas to print/write under format control? In particular, how would i take defined sets of variables per data file record and print/write one set per line in the output?

I understand that if the dataset were restructured so that each case occupied two records, proc print would do it. I'm not very interested figuring out how to restructure a dataset in sas.

I've looked at the proc print documentation and while it can do a lot; i didn't see anything like format control.

Thanks, Gene Maguin

2 REPLIES 2
ballardw
Super User

Without very concrete examples I would say look in the documentation for the Report Writing Interface which provides a LOT of output option/controls including spanned rows and columns.

 

The equivalent of what you are showing can also be done with the basic PUT statement in a data step using the column and line pointer controls to write to either the results window, File Print, or an output file with an external text file referenced on the File statement.

Tom
Super User Tom
Super User

Look for the PUT statement.  You can use formatted values if you want, but that is not required.  If you want that type of list of variable, list of formats syntax then make sure to add () around both lists.  If the format list is too short it is recycled.

put name age sex ;
put name= age= sex=;
put name sex (height weight) (7.3 +1);

You don't even need to know what variables are in the data.

data _null_;
  set sashelp.class(obs=3);
  put (_all_) (=);
run;
137   data _null_;
138     set sashelp.class(obs=3);
139     put name age sex ;
140     put name= age= sex=;
141     put name sex (height weight) (7.3 +1);
142     put (_all_) (=);
143   run;

Alfred 14 M
Name=Alfred Age=14 Sex=M
Alfred M  69.000 112.500
Name=Alfred Sex=M Age=14 Height=69 Weight=112.5
Alice 13 F
Name=Alice Age=13 Sex=F
Alice F  56.500  84.000
Name=Alice Sex=F Age=13 Height=56.5 Weight=84
Barbara 13 F
Name=Barbara Age=13 Sex=F
Barbara F  65.300  98.000
Name=Barbara Sex=F Age=13 Height=65.3 Weight=98

Use the FILE command to direct the output to a file (or the PRINT fileref used for normal output).

 

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 328 views
  • 1 like
  • 3 in conversation