LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2008, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 23 Jul 2008 17:42:55 -0500
Reply-To:     Mary <mlhoward@avalon.net>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Mary <mlhoward@AVALON.NET>
Subject:      Re: Substring a macro variable according to index of a period?
Comments: To: "Fehd, Ronald J. (CDC/CCHIS/NCPHI)" <rjf2@CDC.GOV>
Content-Type: text/plain; charset="iso-8859-1"

Thanks very much; here's my code so far; this reads in all my tab delimited files from a directory and creates both individual data sets as well as a combined data set with a variable added called "datasetname". Obviously you probably wouldn't want to do it this way for 100,000 files, but I do see the need if you need a variable in your final dataset that identifies which file the record came from.

-Mary

options mlogic symbolgen; %macro read; data allset; stop; run; filename exdir "C:\test";

%let dirid = %sysfunc(DOPEN(exdir));

options mlogic symbolgen; %macro read; data allset; stop; run; filename exdir "C:\test";

%let dirid = %sysfunc(DOPEN(exdir)); %let dircnt = %sysfunc(DNUM(&dirid)); %do i = 1 %to &dircnt; %let dirread = %sysfunc(DREAD(&dirid,&i)); %put dirread = &dirread; data temp; informat dummy 1.; stop; run; PROC IMPORT OUT= WORK.temp DATAFILE="C:\test\&dirread" DBMS=TAB REPLACE; GETNAMES=YES; GUESSINGROWS=32767; DATAROW=2; RUN; proc sql noprint; select count(*) as count into :count from temp; quit; %if &count > 0 %then %do; %Let datasetname = %scan(&dirread,1,.); data &datasetname; informat datasetname $50.; set temp; datasetname="&datasetname"; run; data allset; set allset &datasetname; run; %end; %end; %let rc = %sysfunc(DCLOSE(&dirid)); %put rc = &rc;

%mend read;

%read;

----- Original Message ----- From: Fehd, Ronald J. (CDC/CCHIS/NCPHI) To: SAS-L@LISTSERV.UGA.EDU Sent: Wednesday, July 23, 2008 5:00 PM Subject: Re: Substring a macro variable according to index of a period?

Mary:

dot is acceptable as a delimiter of the scan function.

%Let FileNameExt = file1.txt; %Let FileName = %scan(&FileNameExt,1,.); %Put _global_;

note that you scan from the end as well as the beginning:

%Let FolderFileNameExt = c:\temp\file2.txt; %Let FileName = %scan(&FileNameExt,-2,.\); %Put _global_;

Ron Fehd the macro maven CDC Atlanta GA USA RJF2 at cdc dot gov


Back to: Top of message | Previous page | Main SAS-L page