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

Hi,

 

I have two questions which I have listed below. Can anyone help me on it.

 

Let's say, I have a dataset named 'Sample' which is as follows:

 

Sample :

Patient_No   Test1    Test2    Test3

   101                20         30        70

   102                22         32        55

   103                30         50        88

   104                50         29        63

   105                45         60        72

 

1. I want to create a pdf for each single observation, which means I want to create 5 different Pdf files for 5 obs from above dataset. 

 

2. Also, I want to name to those files automatically. Each of the files must have the name as per value from it's 'Patient_No' column. E.g. - pdf file for Patient_No - 101 must have the name as 'Patient 101', for Patient_No 102 it should be 'Patient 102' and so on.

 

 

Can anyone confirm me that is it possible to program the above requirement using sas? If yes, then could you please help me on it?

 

Many Thanks in Advance.

 

Regards,

Vikrant

1 ACCEPTED SOLUTION

Accepted Solutions
VikrantSawatkar
Obsidian | Level 7

Thank you very much Haikuo. It works perfectly. I have another doubt.

I have three datasets named A, B and C which are as follows.

 

                   Dataset A                                       Dataset B                                             Dataset C

PatientName Test1 Test2 Test3       PatientName Test4 Test5 Test6        PatientName Test4 Test5 Test6

   Alex              10      20      30               Alex            50      60      65                Alex             63      65     70

   Sachin          40      50      60              Sachin         30      45      55               Sachin          50      60      65

   Mark             30      45      55              Mark           40      50      60                Mark            10      20      30  

   Ram             63      65     70               Ram            40      50      60                Ram             30      45      55

 

Now I want to export data of the one patient from all 3 datasets into separate pdf (in pdf information from each dataset should appear separate pdf pages). E.g. all the information from 3 datasets of patient let's say Alex should you exported into one pdf (separate page for each dataset) and so on.

 

Many thanks in advance for your help

 

 

View solution in original post

7 REPLIES 7
slchen
Lapis Lazuli | Level 10

Many methods could be used to do it, here is call execute:

data _null_;
   set sashelp.class(obs=3) end=last;
   if _n_ then call execute('ods pdf file=');
   call execute('"c:\temp\name_'||strip(name)||'.pdf" ;
                   proc print data=sashelp.class;
                   where name="'||strip(name)||'";
                   run;
                ');
if last then call execute('ods pdf close;');
run;
Haikuo
Onyx | Level 15

I like this approach. A little mod on your code will output one obs per pdf without 'where' condition.

 

data _null_;
   set sashelp.class(obs=4) end=last;
   if _n_ then call execute('ods pdf file=');
   call symputx('n',_n_);
   call execute('"h:\temp\name_'||strip(name)||'.pdf" ;
                   proc print data=sashelp.class(firstobs=&n obs=&n);
                   /*where name="'||strip(name)||';*/
                   run;
                ');
if last then call execute('ods pdf close;');
run;
VikrantSawatkar
Obsidian | Level 7

Thank you very much Haikuo. It works perfectly. I have another doubt.

I have three datasets named A, B and C which are as follows.

 

                   Dataset A                                       Dataset B                                             Dataset C

PatientName Test1 Test2 Test3       PatientName Test4 Test5 Test6        PatientName Test4 Test5 Test6

   Alex              10      20      30               Alex            50      60      65                Alex             63      65     70

   Sachin          40      50      60              Sachin         30      45      55               Sachin          50      60      65

   Mark             30      45      55              Mark           40      50      60                Mark            10      20      30  

   Ram             63      65     70               Ram            40      50      60                Ram             30      45      55

 

Now I want to export data of the one patient from all 3 datasets into separate pdf (in pdf information from each dataset should appear separate pdf pages). E.g. all the information from 3 datasets of patient let's say Alex should you exported into one pdf (separate page for each dataset) and so on.

 

Many thanks in advance for your help

 

 

Haikuo
Onyx | Level 15

The output part can still be the same, only first merge/join the 3 tables by patientname, assume that they are 1:1 ratio, 

 

proc sq;

create table want as

select * from a, b, c

where a.patientname=b.patientname and a.patientname=c.patientname

;

quit;

VikrantSawatkar
Obsidian | Level 7
Thank you so much.
VikrantSawatkar
Obsidian | Level 7

thank you for your help.

 

But I want to create a pdf for each patient where each record of the patient from each dataset will be created on the separate page. Please consider my previous example. The records the patient let's say 'Alex' is present in 3 datasets. So I want to create a Single Pdf for patient 'Alex' where the exported pdf consists the observations from each dataset into separate pages within it. Means obs for 'Alex' from Dataset A should on 1st page, obs from dataset B on 2nd page and so on.

 

Thank you very much in advance.

Haikuo
Onyx | Level 15

I see you have already posted here two weeks ago, with less details, I must have overlooked, my bad. So condsider the following:


proc sort data=sashelp.class(drop=height) out=no_height;
	by name;
run;

proc sort data=sashelp.class(drop=weight) out=no_weight;
	by name;
run;

proc sort data=sashelp.class(drop=age) out=no_age;
	by name;
run;

data final;
	set no: indsname=dsname;
	by name;
	source=dsname;

	if _n_>6 then
		stop;
run;

data _null_;
	set final end=last;
	by name;

	if first.name then
		call execute('ods pdf file='||'"h:\temp\name_'||strip(name)||'.pdf";' );
	call execute('ods pdf startpage=now;
		proc print data=final(firstobs='||_n_||' obs='||_n_||');
		run;'
		);

	if last then
		call execute('ods pdf close;');
run;

Please note, since your request evolved, so I opted to choose a different merge strategy, rather, it is more like a sorted 'stacking', in order to show the 'source' of your obs.

 

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!

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
  • 7 replies
  • 2376 views
  • 3 likes
  • 3 in conversation