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

I have the following two variables and data:

var1                         align1

Indonesia       3

Japan           4

Panama          2

United Kingdom  5

I want to align the output of the the words, for example, to the 10th space of a column that is 20 spaces wide according to the number given by align1. So for Indonesia 3 means the 3rd character of the word, which means d, Japan 4 means the 4th character a, Panama 2 mean a, and United Kingdom 5 means e. So I want to output:

----|----|----|----|

       Indonesia

      Japan

        Panama

     United Kingdom

What output PROC can I use and what options should I have to achieve this?  I want to output to HTML and PDF, so any further assistance on this would be helpful.

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
iank131
Quartz | Level 8

Putting together the code I received, this is the answer that works best:

Thanks to everyone!

data have;

length var1 $ 20;

input var1 $& align1;

_align=10-align1;

put @_align var1;

datalines;

Indonesia 3

Japan 4

Panama 2

United Kingdom 5

;

title; footnote;

ods listing;

ods pdf file ="c:\temp\useput.pdf" ;

ods html file="c:\temp\useput.html" ;

data have;

  set have;

  file print;

  put @_align var1;

  run;

ods _all_ close;

View solution in original post

6 REPLIES 6
PGStats
Opal | Level 21

You can do it like this :

data have;
length var1 $ 20;
input var1 $& align1;
datalines;
Indonesia       3
Japan           4
Panama          2
United Kingdom  5
;

%let alignPos=10;

proc sql;
create table want as
select cat(repeat(" ", &alignPos.-(max(align1)-align1)), var1) as var
from have;
select * from want;
quit;

PG

PG
Haikuo
Onyx | Level 15

You may just simply do this:

data have;

length var1 $ 20;

input var1 $& align1;

_align=10-align1;

put @_align var1;

datalines;

Indonesia 3

Japan 4

Panama 2

United Kingdom 5

;

Haikuo

Cynthia_sas
SAS Super FREQ

Hi:
The OP said the interest was ODS HTML and/or ODS PDF. The look and feel of the output for those 2 destinations will be different than for LISTING output. Without getting into the issues of writing the output at a variable location (possible). I want to show what the output will look like in PDF and HTML compared to LISTING. If this is what the OP wants, then the ODS "sandwich" would need to be added around your DATA step program and add the FILE PRINT statement.

cynthia

ods listing;

ods pdf file="c:\temp\useput.pdf";

ods html file="c:\temp\useput.html";

data have;

  ** SET statement would go here or INFILE;

file print;

  put @1 '0........1....1....2';

  put @1 '12345....0....5....0';

  put @3 'Indonesia';

  put @4 'Japan';

  put @2 'Panama';

  put @5 'United Kingdom';

run;

ods _all_ close;


file_print_with_put.png
iank131
Quartz | Level 8

Thank you Hai.kuo. Your code was simple and it worked!

Thanks Cynthia for addressing the issues of ODS in PDF and HTML.

Thanks Ksharp for your answers too.

I really appreciate this forum. So many helpful people in such a short time!! Thanks again to all.

Ksharp
Super User

You can use escape char ~_ to instead of a blank in ODS.

data have;
length var1 $ 20;
input var1 $& align1;
datalines;
Indonesia       3
Japan           4
Panama          2
United Kingdom  5
China           1
;
run;
proc sql noprint; select max(align1) into : max from have;quit;
data want;
length var1 $ 100;
 set have;
 if  align1 ne &max then var1=cats(repeat('~_',&max-align1-1),var1);
run;
ods listing close;
ods pdf file="c:\temp\useput.pdf" style=sasweb;
ods html file="c:\temp\useput.html" style=sasweb;
ods escapechar='~';
proc print noobs;run;
ods pdf close;
ods html close;
ods listing;

Ksharp

iank131
Quartz | Level 8

Putting together the code I received, this is the answer that works best:

Thanks to everyone!

data have;

length var1 $ 20;

input var1 $& align1;

_align=10-align1;

put @_align var1;

datalines;

Indonesia 3

Japan 4

Panama 2

United Kingdom 5

;

title; footnote;

ods listing;

ods pdf file ="c:\temp\useput.pdf" ;

ods html file="c:\temp\useput.html" ;

data have;

  set have;

  file print;

  put @_align var1;

  run;

ods _all_ close;

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
  • 6 replies
  • 763 views
  • 9 likes
  • 5 in conversation