Solved
New Contributor
Posts: 3

# Explanation Of SAS Codes

please can someone please explain to me what the following codes do

rc=filename ("fdir","&path");

data _null_;
set dirlist nobs=n;
call symput ('f'||compress(_n_),trim(left(fname)));
call symput ('nf', compress(n));
run;

%do i = 1 %to &nf;
%put &p.\&&f&i;

Accepted Solutions
Solution
‎04-13-2016 06:36 AM
Super User
Posts: 9,599

## Re: Explanation Of SAS Codes

What part of that code do you need expaining, i.e. what is the question?  Judging by this and your other question, you would be best off starting by learning SAS, Base SAS and Macro SAS.  You can learn this by using the help videos given by SAS, doing a course, reading the manual etc.

At a brief glimpse:

rc=filename ("fdir","&path");

rc is a variable which holds the result of calling the function filname.  I.e. rc stands for Return Code.

The below is a macro - a text generation tool - it creates some macro varibales and then start to DO a loop.  You are missing a % before macro, and my first question would be why are you doing it this way in the first place?

data _null_;
set dirlist nobs=n;
call symput ('f'||compress(_n_),trim(left(fname)));
call symput ('nf', compress(n));
run;

%do i = 1 %to &nf;
%put &p.\&&f&i;

All Replies
Solution
‎04-13-2016 06:36 AM
Super User
Posts: 9,599

## Re: Explanation Of SAS Codes

What part of that code do you need expaining, i.e. what is the question?  Judging by this and your other question, you would be best off starting by learning SAS, Base SAS and Macro SAS.  You can learn this by using the help videos given by SAS, doing a course, reading the manual etc.

At a brief glimpse:

rc=filename ("fdir","&path");

rc is a variable which holds the result of calling the function filname.  I.e. rc stands for Return Code.

The below is a macro - a text generation tool - it creates some macro varibales and then start to DO a loop.  You are missing a % before macro, and my first question would be why are you doing it this way in the first place?

data _null_;
set dirlist nobs=n;
call symput ('f'||compress(_n_),trim(left(fname)));
call symput ('nf', compress(n));
run;

%do i = 1 %to &nf;
%put &p.\&&f&i;

Super User
Posts: 10,270

## Re: Explanation Of SAS Codes

Everytime you see a statement/function/format/whatever you're not familiar with, enter "SAS whatever_you_want_to_know_about" into big G, and you'll get the respective documentation, most often as the first hit.

It's what I do when I stumble across something I haven't seen yet, or haven't used for a long time, or am not very familiar yet.

All the "old hands" around here do it.

If you then have a more specific question, come here. But this community is intended as a help for advanced problems, not as the place for initial learning. This is done in the courses you have already been pointed to.

We're the track&field coaches and dance instructors, but we expect you already have learned how to walk.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
🔒 This topic is solved and locked.