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

Hello programmers,

 

I have a dataset that i want to put out in the form like in the picture attached.

 

I have tried to use the data _null_ /file print routines but i think i'm missing something that may help me get the form that i am looking for.

 

I want to output the dataset into two pages. With the first page showing output for run=1 and the second page showing output for run=2. 

 

I was told that my variable table did not initialize. Please what could be the problem? Any help would be appreciated!

 

data AAA;
input  grporder	grpname $	Tc	Tn $	Mean_baseline	Mean_12_months		std_baseline	std_12_months prob_change	run;
datalines;
1	Motor 	2	UHDRS	32.8571	29.7143	6.2029	7.5435	0.29688	1
1	Motor 	3	CHOREA	11.8571	10.1429	3.7607	1.8645	0.15625	1
1	Motor 	4	GAIT	1.2857	1.2857	0.488	0.7559	1	1
1	Motor 	5	TANDEM	1.8571	1.5714	1.069	1.3973	0.75	1
1	Motor 	6	PULL	0.1429	0.7143	0.378	0.7559	0.125	1
1	Motor 	7	BALANCE	3.2857	3.5714	1.3801	2.6367	1	1
2	Physical	1	TFC	6.5714	7	0.9759	2.1602	0.625	1
2	Physical 	13	FA	20.2857	19.1429	2.2147	3.2367	0.3125	1
2	Physical 	14	IS	77.1429	71.4286	8.5912	7.4801	0.28125	1
3	Cognigtive 	8	COWA	27.1667	31.5	8.2321	13.896	0.1875	1
3	Cognigtive	9	SYMBAL 	25.1429	20.1429	5.113	7.1514	0.09375	1
3	Cognigtive	10	STROOP 1	45.8571	38.2857	13.5576	17.1437	0.04688	1
3	Cognigtive 	11	STROOP 2	61.7143	52.2857	19.414	22.5367	0.03125	1
3	Cognigtive	12	STROOP 3	29.4286	28.1429	9.6065	10.4152	0.40625	1
3	Cognigtive	15	MMSE	27.5	26.8333	2.51	2.6394	0.625	1
1	Motor 	2	UHDRS	33.8333	27.5	6.1779	5.2058	0.03125	2
1	Motor 	3	CHOREA	12.1667	10.3333	4.0208	1.9664	0.1875	2
1	Motor 	4	GAIT	1.3333	1.1667	0.5164	0.7528	1	2
1	Motor 	5	TANDEM	1.8333	1.1667	1.169	0.9832	0.25	2
1	Motor 	6	PULL	0	0.5	0	0.5477	0.25	2
1	Motor 	7	BALANCE 	3.1667	2.8333	1.472	1.9408	0.5	2
2	Physical	1	TFC	6.6667	7.5	1.0328	1.8708	0.25	2
2	Physical 	13	FA	20.6667	20.1667	2.1602	1.9408	0.625	2
2	Physical 	14	IS	78.3333	73.3333	8.756	6.0553	0.5	2
3	Cognigtive 	8	COWA	29.2	35	7.328	12.227	0.125	2
3	Cognigtive	9	SYMBAL 	25.6667	21.5	5.3914	6.775	0.1875	2
3	Cognigtive	10	STROOP 1	45.5	39.1667	14.8155	18.6056	0.09375	2
3	Cognigtive 	11	STROOP 2	61.3333	52.8333	21.2383	24.6367	0.0625	2
3	Cognigtive	12	STROOP 3	29.1667	28	10.496	11.4018	0.625	2
3	Cognigtive	15	MMSE	27.6	27.2	2.7928	2.7749	0.875	2
; run;
proc print; run;
proc sort data=AAA; by run grporder grpname tc tn;run;
data BBB ; set AAA; by run grporder grpname tc tn; 
options nodate nonumber; 
file print notitles header = newpage;
if first.run then put _page_;
if first.grpname then put tn $33.  @;   
put @ 1 'Including pt 5' table 1.; 
put @30 'Mean_baseline' @40 'std_baseline' @50 'Mean_12_months' @60 'Std_12_months'    @70 'prob_change' ;  
return; 
newpage:
if last.run then put _page_;
if last.grpname then put tn $33. @;
put @ 1 'Excluding pt 5' tbale 2.;
put @30 'Mean_baseline' @40 'std_baseline' @50 'Mean_12_months' @60 'Std_12_months'    @70 'prob_change' ;  
return; 
run;

1.JPG

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

What values go into those cells?

It really looks like you are intending some sort of summary since your example data has at least 12 values of "motor" but your table example only shows one row with "motor" for the group name. Depending on the actual desired values of your cells this might be a better case for proc report.

Either that or your example doesn't match the data orders at all.

 

FILE PRINT ODS in a data step will make prettier tables in the ods destinations.

PUT _ODS_ to control output, which uses ODS column numbers instead of character spaces to play with values.

 

I have done manual tables, much nastier than your examples, to include using proprietary markup language to make pretty tables and would avoid most of that like a plague if at all possible. We had to play around with changing table definitions just because a value showed up that took more space with the same number of letters because W is wider than most other letters.

View solution in original post

7 REPLIES 7
Reeza
Super User
Why don't you just create a table and use PROC PRINT or PROC REPORT? Or do you need structured text files?

ChuksManuel
Pyrite | Level 9

Thanks!

 

Please can't i do it using this method?

Reeza
Super User
You can do whatever you want, but not sure what you're planning to prepare here. Most people want data in Excel or Word files these days, not text files.

put @ 1 'Including pt 5' table 1.;

You should post your log, as we've indicated many times it tells usually where the error is. I suspect its in that line and you don't have a variable table so not sure what value you're trying to refer to there.

If you use search on your program you'll see the first reference to table is in your PUT statement. I'll leave it to you to debug it from there.
ChuksManuel
Pyrite | Level 9
242  data BBB ; set AAA; by run grporder grpname tc tn;
243  options nodate nonumber;
244  file print notitles header = newpage;
245  if first.run then put _page_;
246  if first.grpname then put tn $33.  @;
247  put @ 1 'Including pt 5' table 1.;
248  put @30 'Mean_baseline' @40 'std_baseline' @50 'Mean_12_months' @60 'Std_12_months'    @70
248! 'prob_change' ;
249  return;
250  newpage:
251  if first.run then put _page_;
252  if first.grpname then put tn $33. @;
253  put @ 1 'Excluding pt 5' table 2.;
254  put @30 'Mean_baseline' @40 'std_baseline' @50 'Mean_12_months' @60 'Std_12_months'    @70
254! 'prob_change' ;
255  return;
256  run;

NOTE: Variable table is uninitialized.
NOTE: 76 lines were written to file PRINT.
NOTE: There were 30 observations read from the data set WORK.AAA.
NOTE: The data set WORK.BBB has 30 observations and 11 variables.
NOTE: DATA statement used (Total process time):
      real time           0.06 seconds
      cpu time            0.06 seconds

Reeza
Super User
Did you mean to include some text with that post. Not sure what that's supposed to show. SAS is telling you that you don't have a variable called TABLE, which from the code you've show appears to be correct. There is no variable named TABLE.
Kurt_Bremser
Super User

Maxim 3: Know Your Data.

There is no variable table in dataset AAA, but you try to use it in the output. Therefore you only get missing values.

See if you misspelled the variable, here or further up in the code where you created it.

ballardw
Super User

What values go into those cells?

It really looks like you are intending some sort of summary since your example data has at least 12 values of "motor" but your table example only shows one row with "motor" for the group name. Depending on the actual desired values of your cells this might be a better case for proc report.

Either that or your example doesn't match the data orders at all.

 

FILE PRINT ODS in a data step will make prettier tables in the ods destinations.

PUT _ODS_ to control output, which uses ODS column numbers instead of character spaces to play with values.

 

I have done manual tables, much nastier than your examples, to include using proprietary markup language to make pretty tables and would avoid most of that like a plague if at all possible. We had to play around with changing table definitions just because a value showed up that took more space with the same number of letters because W is wider than most other letters.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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