DATA Step, Macro, Functions and more

Explanation Of SAS Codes

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Explanation Of SAS Codes

 

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

 

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

 

macro readf(p);
 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
Super User
Posts: 7,401

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?

macro readf(p);
 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;

View solution in original post


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

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?

macro readf(p);
 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: 6,936

Re: Explanation Of SAS Codes

Google is your friend. Really. I mean it.

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
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 214 views
  • 0 likes
  • 3 in conversation