Suggest you explore using the SAS DATA step technique with multiple OUTPUTs, one for each file, and as you mentioned, using IF FIRST. to increment a count variable. Then use the SAS OUTPUT statement to send an observation to an output file name based on the incrementing variable. Then code your PROC PRINT steps, one for each split-file.
Another option is using SAS MACRO language concept with a macro coded using %DO and %END; to process your input records and generate "n" output files. A list of COUNTRY values can be generated with PROC SQL, generating a list of SAS macro variables, for which you would process each in your macro to create a split-file, and then print it.
The SAS support website http://support.sas.com/ has SAS hosted documentation, and also there are technical papers on this type of topic. Suggest you consider using the SEARCH facility at the website to identify references related to your post and also check the archives for this forum.
Here is one of the technical conference papers I found using the SAS support website SEARCH facility:
WHAT WOULD I DO WITHOUT PROC SQL AND THE MACRO LANGUAGE
Jeff Abolafia, Rho, Inc., Chapel Hill, NC
In addition to other comments, it's also hard to imagine why you want #1 (a separate data set for every country) when you can achieve #2 with a simple PROC PRINT and BY group processing. Assuming the file is sorted by country, then you can simply use BY statements with NEWFILE=BYGROUP (in HTML, RTF or PDF and some few other destinations. You'd need PAGEBY in the LISTING destination to get every country on a separate page).
The reason I found your post confusing was that if ALL you wanted was a separate dataset for every country so you could do a PROC PRINT, there would be no need for tracking first.byvar or last.byvar unless you needed to ALSO reset some counter variable or accumulator variable for each country OR you wanted to only output 1 observation per country. So, that piece of your post just did not make sense to me.
ods html file='c:\temp\county1.html' style=sasweb
title 'New Proc Print for Every ByGroup';
proc print data=countynm1;
var country reading;
ods html close;
SET COUNTYDT END=EOF; /* READ SAS DATASET */
BY COUNTYNM; /* SORT SEQ */
IF FIRST.COUNTYNM THEN DO; /* NEW COUNTY ? */
NUMCTY+1; /* ADD 1 TO NUMCTY */
CTYOBS=0; /* OBS PER COUNTY TO 0 */
CTYOBS+1; /* ADD ONE OBSER FOR CTY */
IF LAST.COUNTYNM THEN DO; /* EOF CTY, MAKE MAC VARS*/
IF EOF THEN
CALL SYMPUT('MTOTCT',NUMCTY); /* MAC VAR NO DIF CTYS */
%PUT *** MTOTCT=&MTOTCT; /* DISPLAY NO OF CTYS */
%MACRO COUNTYMC; /* MACRO START */
%DO I=1 %TO &MTOTCT; /* LOOP THRU ALL CTYS */
%PUT *** LOOP &I OF &MTOTCT; /* DISPLAY PROGRESS */
PROC PRINT DATA=COUNTYDT; /* PROC PRINT */
WHERE COUNTYNM="&&MCTY&I"; /* GENERATED WHERE */
OPTIONS PAGENO=1; /* RESET PAGENO */
TITLE "REPORT FOR COUNTY &&MCTY&I";
/* TITLES AND FOOTNOTES */
FOOTNOTE "TOTAL OBSERVATION COUNT WAS &&MOBS&I";
%END; /* END OF %DO */
%MEND COUNTYMC; /* END OF MACRO */
%COUNTYMC /* INVOKE MACRO */
Message was edited by: Main