BookmarkSubscribeRSS Feed
Trog
Calcite | Level 5
Hi Guys
Am Rusty at this, so please excuse the dumb question - but its driving me mad!

Start Point
I have to read a large SAS file where each record contains (amongst other things) a char field NAM containing a variable name i.e 123abc99qz.

This field is part of a full path id for a SAS Library i.e. /DIR1/DIR2/DIR3/123abc99qz/DIR4/.

So, for each record on the input SAS file I need to:
(1)Extract the NAM variable & Create the full path id . I do it thus :

DATA FRED1;
Attrib FULL_PATH Length Length=$40;
Set INPUT_FILE(Keep=NAM);
FULL_PATH = '/PATH1/PATH2/' || NAM || '/PATH4/';
ARRAY FP_ARRAY (1) $ FULL_PATH;
/* each FP_ARRAY variable now contains a valid SAS Library name */
RUN;

(2) I now need to assign the value of each iteration of FULL_PATH to a variable that I can use to allocate a libname......
DO I = 1 to DIM(FP_ARRAY)
CALL SYMPUT ('LIB_ID',FP_ARRAY(i));
LIBNAME LIBLIB "&LIB_ID".


END;

(2)Run Proc sort on a filename in this Library with "out=" & "where" parameters.
Easy - once the Library can be assigned
PROC SORT DATA=LIBLIB.filename;
OUT=CUT1;
WHERE();
(3)Run Proc Append to add the out= file specified previously to a permanent D/Set
(Again - Easy once the Library is assigned)

(4) Read the next record on the File untill all are processed.

I know that all processing must be done within FRED1 else the array will disappear...but it has me tearing my hair out.

Any advice on how to proceed (or indeed, an alternate processing suggestion) would be most appreciated.
5 REPLIES 5
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
If not interested in using MACRO language, consider using CALL EXECUTE to assign a SAS variable that contains each of your well-defined PROC steps. No array needed - just generate the SAS code and the steps will be executed serially after your main DATA step completes.

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
Hi Scott
Its not that i'm not interested in using the Macro language - I'm happy to use anything that works!.
Thanks for your advice

Best regards,

Trog
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
It's only that using MACRO language increased the PITA effect for debugging, because....let's see, where should I start...NO LINE NUMBERS REVEALED!! Sorry, increased cuban coffee consumption this Friday. Understandably, some have an aversion to embracing the SAS macro language unless absolutely required.

Scott Barry
SBBWorks, Inc.
Cynthia_sas
SAS Super FREQ
Hi:
One trick that we used to use at a company that would not let SAS Macro programs in a production (scheduled job) was to do this:

[pre]
data _null_;
file 'yadayada.sas';
build statements in code and then PUT them to flat file;
run;

%include 'yadayada.sas';
[/pre]

One advantage of this is that you can keep examining the "yadayada.sas" file to see that it's got the correct statements. We were allowed %include or SYSIN DD -- so it was a different approach but might work in this case.

cynthia
Patrick
Opal | Level 21
Hi Trog
Here a code example for what others already described:

data have;
var1='c:\';
NAM='tests';
output;
var1='c:\';
NAM='tests2';
output;
run;

%macro DoSomething(PathPart=,NamVal=,ds=hugo);
%let path=&PathPart.&NamVal;
libname xx "&path" access=readonly;
proc sort data=xx.&ds out=work.&ds;
by country;
run;
libname xx clear;
libname yy 'c:\tests3';
proc append base=yy.AllTogether data=work.&ds force;
run;
libname yy clear;
%mend;

data _null_;
set have;
call execute ('%DoSomething(PathPart='||var1||',NamVal='||Nam||')');
run;


HTH
Patrick

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1241 views
  • 0 likes
  • 5 in conversation