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

Dear experts.

I have a requirement to create a new variable to use it in my proc report to do the alignment as per data

the requirement is

I want to create pnum variable  to get each test in one page in the report (i.e in one page different tests should not come) but in one page it can accommodate only 5 records .So that Iam creating pnum for first 5 test as 1 and next till the end of same test should be 2 . 

same like for the next test "urin" first 5 is 3 and the rest is 4

 

like that i have so many tests ..

 

So if i create a variable like this I can use that in the report as page break 

x  test    r  pnum

1 blood 1   1
1 blood 2   1
1 blood 3   1
1 blood 4   1
1 blood 5   1
1 blood 6   2
1 blood 7   2
1 blood 8   2
2 urin   9   3
2 urin 10   3
2 urin 11   3
2 urin 12   3
2 urin 13   3
2 urin 14   4

 

1 ACCEPTED SOLUTION

Accepted Solutions
LeonidBatkhan
Lapis Lazuli | Level 10

Hi ambadi007,

 

You can do this as shown in the code example below:

data A;
   length x 8 test $10;
   input x test;
   datalines;
1 blood
1 blood
1 blood
1 blood
1 blood
1 blood
1 blood
1 blood
2 urin 
2 urin
2 urin
2 urin
2 urin
2 urin
;

proc sort data=A out=B;
   by x;
run;

data C (drop=count);
   set B;
   by x;
   r = _n_;
   if first.x then count=0;
   count + 1;
   if mod(count-1, 5)=0 then pnum + 1;
run;

Hope this helps.

View solution in original post

1 REPLY 1
LeonidBatkhan
Lapis Lazuli | Level 10

Hi ambadi007,

 

You can do this as shown in the code example below:

data A;
   length x 8 test $10;
   input x test;
   datalines;
1 blood
1 blood
1 blood
1 blood
1 blood
1 blood
1 blood
1 blood
2 urin 
2 urin
2 urin
2 urin
2 urin
2 urin
;

proc sort data=A out=B;
   by x;
run;

data C (drop=count);
   set B;
   by x;
   r = _n_;
   if first.x then count=0;
   count + 1;
   if mod(count-1, 5)=0 then pnum + 1;
run;

Hope this helps.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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
  • 1 reply
  • 330 views
  • 0 likes
  • 2 in conversation