how to create a dummy template if a particular variable does not exist

Accepted Solution Solved
Reply
Contributor VRD
Contributor
Posts: 33
Accepted Solution

how to create a dummy template if a particular variable does not exist

I want to create a template like before proc report.

i have 2 treatment groups and many trials. But in some trials i only have 1 treatment group. the problem is i get error for that trials when i pass them as there is no other treatment.

proc report data=final nowd headline headskip spacing = 1 split = "|" missing;

    columns("&line." week_char exc ('-------------A--------------------'A1  A2)

           ('-------------B --------------' B1  B2));

    define week_char  / group           order=data ' ' Width=10 spacing=2;

    define exc   /     order=data ' ' Width=15 spacing=2;

    define A1/ display ' A1' width=22 spacing=2;

    define A2/ display 'A2' width=22 spacing=2;

    define B1/ display ' B1' width=22 spacing=2;

    define B2/ display '  B2' width=22 spacing=2;

    break after week_char/skip;

run;

in this if i pass one trial i get both trtments but for some trials i only have A trtment. I need to show even B tretament even if it doesnt exist.

Can any one guide me in this


Accepted Solutions
Solution
‎06-24-2014 04:31 AM
Super User
Super User
Posts: 7,405

Re: how to create a dummy template if a particular variable does not exist

Create an empty table with all the variables you expect, then set this with your results, will always make sure you have the ones you want.  TBH though from my point of view, you should be doing this at the creation of your results.  My procedure is always create the dataset structure as you want to see it, then fill the data in.  Its easier than trying to figure out what columns you have later on (especially when transposing).

proc sql;

     create table TEMPLATE

     (

          TRTA char(200),

          TRTB char(200)

     );

quit;

data your_results;

     set your_results template;

run;

View solution in original post


All Replies
Solution
‎06-24-2014 04:31 AM
Super User
Super User
Posts: 7,405

Re: how to create a dummy template if a particular variable does not exist

Create an empty table with all the variables you expect, then set this with your results, will always make sure you have the ones you want.  TBH though from my point of view, you should be doing this at the creation of your results.  My procedure is always create the dataset structure as you want to see it, then fill the data in.  Its easier than trying to figure out what columns you have later on (especially when transposing).

proc sql;

     create table TEMPLATE

     (

          TRTA char(200),

          TRTB char(200)

     );

quit;

data your_results;

     set your_results template;

run;

Contributor VRD
Contributor
Posts: 33

Re: how to create a dummy template if a particular variable does not exist

Thanks for the reply. what is i want to replace the missing by 0.

Super User
Super User
Posts: 7,405

Re: how to create a dummy template if a particular variable does not exist

Just add an if to the set:

data your_results;

     set your_results template;

     if trta="" then trta="0";

     if trtb="" then trtb="0";

run;

Or best of making them numeric and using the missing=0; option.

Contributor VRD
Contributor
Posts: 33

Re: how to create a dummy template if a particular variable does not exist

Thanks a lot.

I have a last query on this as i want to know different possibilities on this.

What if in this case if there is no treatment then i should display the group. like if i have only treatment A and not be then my proc report output should come only for treatementA. If i have both treatments than it should display both.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 230 views
  • 3 likes
  • 2 in conversation