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 18:00:13 -0400
Reply-To:     "Fehd, Ronald J. (CDC/CCHIS/NCPHI)" <rjf2@CDC.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Fehd, Ronald J. (CDC/CCHIS/NCPHI)" <rjf2@CDC.GOV>
Subject:      Re: Substring a macro variable according to index of a period?
In-Reply-To:  <021401c8ed0d$b6e8b180$832fa8c0@HP82083701405>
Content-Type: text/plain; charset=us-ascii

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

> -----Original Message----- > From: owner-sas-l@listserv.uga.edu > [mailto:owner-sas-l@listserv.uga.edu] On Behalf Of Mary > Sent: Wednesday, July 23, 2008 5:48 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Substring a macro variable according to index of a period? > > Hi, > > I'm trying to adapt Rodney's code to mine, reading in > tab-delimited files. > Below works to load all files from a directory into SAS data > sets as temp1, > temp2, etc., but I would prefer to have the name of the data > set be the name > of the file, but up to the file extension, i.e., excluding > the ".txt" in > this case. > > The macro variable, "dirread" below contains the full > filename, such as > file1.txt. Does anyone know how to search (index) a macro > variable for the > position of the period, and then substring the macro variable > for the string > to the left of the period? I would like a macro variable such as > &datasetname to be the portion of &dirread to the left of > the .txt, for > instance "file1" if drread is "file1.txt", then instead of > temp&i I could > use &datasetname. > > -Mary > > Options mprint mlogic symbolgen; > %macro read; > filename exdir "C:\Work_Activities\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:\Work_Activities\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; > data temp&i; > set temp; > run; > %end; > %end; > %let rc = %sysfunc(DCLOSE(&dirid)); > %put rc = &rc; > %mend read; > %read; > >


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