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
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.
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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.