BookmarkSubscribeRSS Feed
R_Win
Calcite | Level 5
data countynm1;
input Obs COUNTRY$:10. READING;
cards;
1 LAND 125
2 LAND 611
3 BAY 101
4 BAY 101
5 BAY 222
6 WASHINGTON 143
run;


I want like this
1. Create a separate dataset for each reporting country.
2. Produce a separate PROC PRINT for each reporting county.

Message was edited by: Main Message was edited by: Main
6 REPLIES 6
deleted_user
Not applicable
Surely this is a forum for asking questions not simply demanding solutions.
R_Win
Calcite | Level 5
HI i have quoted my question not demanded as i framed that sentence like this as i quoted the query that is the way i want the answer .i also know this is a forum no on demand .If u know Reply to it.
deleted_user
Not applicable
There is no question in your post.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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

http://www2.sas.com/proceedings/sugi30/031-30.pdf


SAS MACRO language -- Using PROC SQL with the SAS Macro Facility

http://support.sas.com/documentation/cdl/en/sqlproc/62086/HTML/default/a001360983.htm

-- Creating and Using Macro Variables
http://support.sas.com/documentation/cdl/en/sqlproc/62086/HTML/default/a002595788.htm


Suggest developing a SAS program to accomplish your objective, re-post a reply with the code, for feedback from the forum.

Scott Barry
SBBWorks, Inc.
Cynthia_sas
SAS Super FREQ
Hi,
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.

cynthia

[pre]
ods listing;
ods html file='c:\temp\county1.html' style=sasweb
newfile=bygroup;
title 'New Proc Print for Every ByGroup';
proc print data=countynm1;
by country;
pageby country;
var country reading;
sum reading;
run;
ods html close;
[/pre]
R_Win
Calcite | Level 5
DATA _NULL_;
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 */
END;
CTYOBS+1; /* ADD ONE OBSER FOR CTY */
IF LAST.COUNTYNM THEN DO; /* EOF CTY, MAKE MAC VARS*/
CALL SYMPUT('MCTY'||LEFT(PUT(NUMCTY,3.)),COUNTYNM);
CALL SYMPUT('MOBS'||LEFT(PUT(NUMCTY,3.)),LEFT(CTYOBS));
END;
IF EOF THEN
CALL SYMPUT('MTOTCT',NUMCTY); /* MAC VAR NO DIF CTYS */
RUN;
%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";
RUN;
%END; /* END OF %DO */
%MEND COUNTYMC; /* END OF MACRO */
%COUNTYMC /* INVOKE MACRO */ Message was edited by: Main

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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