BookmarkSubscribeRSS Feed
jreilly620
Calcite | Level 5

This is probably a simple question.  Using put how would I created output like this

Degree   Major

MA        Music

             Education

PHd        Music         

    My issue is on I want leading blanks on the third line.  SAS pulls the word education back to the first column.  I have tried @ for column etc and have not been able to get it to work.  Degree and major are fields on the record.  I don't want to repeat MA if the degree is a double major.  Thanks for you help.  

J

6 REPLIES 6
Doc_Duke
Rhodochrosite | Level 12

J.

Knowing the task you are using might help on a different answer.  Sometimes it is the destination that is realigning things rather than SAS.

Doc Muhlbaier

Duke

jreilly620
Calcite | Level 5

Doc this is what I am trying to do see below.  Thank you.

John

This is what I am trying to do

data _null_;

OPTIONS Missing='';

    retain old_degree '   ';

    retain old_seq_no '  ';

       

    set Query_for_SORDEGR_II;

    file tmp1 mod;

    if _n_ = 1 then do;

        put '---'

        /

        'Degree Information: '

        ;

    end;

    If old_seq_no NE seq_no then do;

    put

    Degree $5.

    @10 '---> Major:' Major $30.

    @55 '---> School:' School $30.

    ;

    end;

    If  old_seq_no = seq_no then do;

    put

   '      '    I want to put in leading spaces and by if two majors equal to the degree output above ******

    @10 '---> Major:' Major $30.

    @55 '---> School:' School $30.

    ;

    end;

   old_degree = Degree;

   old_seq_no = seq_no ;

  ;

    ;

Cynthia_sas
SAS Super FREQ


Hi:

  As Doc suggests, knowing the task (procedure code) and destination, would be useful. Your reference to @ is confusing, because with TAGSETS.EXCELXP or MSOFFICE2K, @ is frequently used to indicate that a number should be treated as text when your report is rendered by Excel. However, your variable, DEGREE appears to be character, so that doesn't make sense.

  Consider the PROC REPORT code below. Note how the repetitious display of NAME and DEGREE are suppressed where appropriate. This isn't exactly the same thing as "leading" spaces.

  But, depending on what you mean by "leading spaces", the procedure that you're using (task) and the destination that you're using, you might or might not be able to use PROC REPORT. On the other hand, if you are using PUT statements to write the rows, then leading spaces are generally suppressed by ODS, unless you set a style attribute (ASIS=ON) to have leading spaces respected. You might want to work with Tech Support on this question. They can look at ALL your code or your task code and your data and help you figure out te solution.

cynthia

data majors;

  length name $8 degree $12 major $15;

  infile datalines;

  input name $ degree $ major $;

return;

datalines;

alan  MA Music

alan  MA Education

alan  PhD Music

barb  BA  Art

barb  BA  Business

barb  MFA Art

barb  MBA Marketing

barb  DBA Markerting

carl  MA  Music

carl  PhD Music

carl  EdD Education

;

run;

  

ods listing close;

title; footnote;

  

ods html file='c:\temp\degrees.html' style=journal;

   

proc report data=majors nowd;

  column name degree major;

  define name / order;

  define degree / order order=data;

  define major / display;

run;

ods html close;


blank_out_repeat_values.png
Howles
Quartz | Level 8

Maybe this is satisfactory:

proc sort data=majors ;

by name degree major ;

run ;

proc print data=majors ;

by name degree ;

id name degree ;

run ;

jreilly620
Calcite | Level 5

Cynthia,

    This is what I am trying to do.  TY.

John

data _null_;

OPTIONS Missing='';

    retain old_degree '   ';

    retain old_seq_no '  ';

       

    set Query_for_SORDEGR_II;

    file tmp1 mod;

    if _n_ = 1 then do;

        put '---'

        /

        'Degree Information: '

        ;

    end;

    If old_seq_no NE seq_no then do;

    put

    Degree $5.

    @10 '---> Major:' Major $30.

    @55 '---> School:' School $30.

    ;

    end;

    If  old_seq_no = seq_no then do;

    put

    '      ' I want to put in leading spaces and by if two majors equal to the degree output above ******

    @10 '---> Major:' Major $30.

    @55 '---> School:' School $30.

    ;

    end;

   old_degree = Degree;

   old_seq_no = seq_no ;

  ;

    ;

Cynthia_sas
SAS Super FREQ

Hi:

  Thanks! Now I understand your use of @ -- with PUT statements. What you did NOT tell us was your destination of choice -- whether you have HTML turned on, SASReport turned on, RTF or PDF, etc (you can find out by looking under Tools-->Options-->Results General). I do not see any explicit ODS statements in your code, so I think that you are probably either using HTML or SASReport destination. But it's a moot point. With SAS and ODS, your simple PUT @10, PUT @55, etc will not produce any type of output that you will like. The fact is that most things in ODS are written in a proportional spaced font, whereas, the PUT statement was designed for a world where printers did NOT have proportional spaced fonts.

  Also, are you interested in only writing to the SAS log? I do not see any FILE statements in your code. I would have expected to see either

FILE 'c:\temp\myflatfile.txt'; or

FILE PRINT;

in the code. So I'm sort of wondering where you are getting your results. (This is related to the destination that you've chosen for your output.)

  As an example, consider the following "line" of text. Each "line" contains 25 letters. Exactly 25 letters.

Arial font:

iiiiiiiiiiiiiiiiiiiiiiiii

wwwwwwwwwwwwwwwwwwwwwwwww

and you can see that @10 in the string of the letter 'i' does not "line up" with @10 in the string of the letter 'w'.

Courier New font:

iiiiiiiiiiiiiiiiiiiiiiiii

wwwwwwwwwwwwwwwwwwwwwwwww 

so, even though the 'i' and the 'w' both line up in position 10 in the Courier New font, placing text in absolute column positions is still hard with ODS because many of the conventions that folks used to use in these old type of DATA _NULL_ programs just don't work anymore. The default in ODS is for leading spaces to be suppressed in text, as an example of just one thing. The use of PUT _PAGE_ is another thing that doesn't work.

Next, your logic, while it makes sense, is unnecessary, (you could use BY group processing to detect the first seq_no or degree in a group). But even BY group processing, while probably easier to code, would still be inside a sub-optimal DATA _NULL_ program.

And, besides, either the PROC PRINT example or the PROC REPORT example, will build you a table and suppress duplicate observations far easier than doing your own coding. Why is the DATA _NULL_ approach being used? You have created data from some kind of query (guessing from the name) -- why not use the List Data task or the List Report task or the code that's been provided to get you a report?

If you use the EGDEFAULT style, then your report table will look like it has interior table lines. But, as I show in my code and screenshot, if you change to the JOURNAL style, your report will not have interior lines, and it will look like you have leading spaces in the DEGREE column. Did you try either the PROC PRINT or the PROC REPORT code?

If you really, really want to use DATA _NULL_, then you'll probably have to work with Tech Support to figure out how to write a style template that will use a monospace font, such as Courier New for your output, and you will have to set the ASIS style attribute to ON for selected style elements. And, you still have to figure out whether any of those techniques will work with your chosen destination, whatever it is.   To open a track with Tech Support, fill out the form at this link: http://support.sas.com/ctx/supportform/createForm

cynthia

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1145 views
  • 0 likes
  • 4 in conversation