Help using Base SAS procedures

SAS File I/O Functions

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 90
Accepted Solution

SAS File I/O Functions

Hello Everyone,

I am a little stuck on this problem for my homework.

The problem is:

  1. Use PROC FCMP to create a function named Nums that takes one argument, which is the name of a SAS data set, and returns the number of logical observations in the data set. Refer to SAS OnlineDoc or the SAS Help facility to determine which SAS FILE I/O functions are required.

I have tried to look at the online doc for help on this, but I could not find a SAS File I/O function that would work for the program that I have currently:

proc fcmp outlib=work.functions.Marketing;

  function Nums(dataset) $40;

     return (open(dataset));

  endsub;

  run;

  quit;

*part b;

data _null_;

   x=Nums('orion.Internet');

   put x=;

run;

Could someone please let me know what SAS File I/O I should use in order for this program to return correctly?

Thanks,

Alisa


Accepted Solutions
Solution
‎05-07-2012 05:10 PM
Trusted Advisor
Posts: 1,300

Re: SAS File I/O Functions

proc fcmp;

function num(dataset $);

  dsid=open(dataset);

   nobs=attrn(dsid,"nobs");

  rc=close(dsid);

  return(nobs);

endsub;

test=num('sashelp.class');

put test;

run;

View solution in original post


All Replies
Solution
‎05-07-2012 05:10 PM
Trusted Advisor
Posts: 1,300

Re: SAS File I/O Functions

proc fcmp;

function num(dataset $);

  dsid=open(dataset);

   nobs=attrn(dsid,"nobs");

  rc=close(dsid);

  return(nobs);

endsub;

test=num('sashelp.class');

put test;

run;

Frequent Contributor
Posts: 90

Re: SAS File I/O Functions

Thanks FriedEgg! Smiley Happy This was very helpful!

Nice to get help from another Coloradan! Smiley Happy

Cheers!

Alisa

Trusted Advisor
Posts: 1,300

Re: SAS File I/O Functions

If you are a student keep me in mind when you are ready to search for a job.  I am almost always looking for to hire one or two SAS users at varying levels.  Currently I have two positions open for expert level positions and I just closed one for an entry level SAS user.

Super Contributor
Posts: 1,636

Re: SAS File I/O Functions

Hi FE,

Does your company allow working remotely?  Thank you!

Trusted Advisor
Posts: 1,300

Re: SAS File I/O Functions

Not for entry level positions.  Typically we will only have programmers working remotely after they have already worked in one of our offices for an extended period of time.  Especially for beginner and intermediate level positions.  One of the positions I have at this time could work from our office in New York instead of Colorado, this would be for an expert level SAS statistical programmer and researcher.

Here are the positions I currently have available:

Statistical Analyst - Harrison, New York (remote possible, but unlikely)

Sr. Statistical Analyst - Harrison, New York (remote is a possibility)

Production Operations Programmer - Louisville, CO (This is a entry level position, remote to start i...

SAS Programmer - Louisville, CO (This is a intermediate to expert level position, and the one I am m...

Super Contributor
Posts: 1,636

Re: SAS File I/O Functions

Thank you!!!  -Linlin

Frequent Contributor
Posts: 90

Re: SAS File I/O Functions

Hi FriedEgg,

I will definitely keep you in mind! I am currently working on my Prob-Stat undergrad at Metro and I will be graduating Sprint 2013.

Do you have a LinkedIn page?

Cheers!

Alisa

Trusted Advisor
Posts: 1,300

Re: SAS File I/O Functions

There is a link to my LinkedIn page on my profile for this site.  Just click on my name.

Super User
Posts: 5,076

Re: SAS File I/O Functions

Good code, but a slight change is in order.  The number of "logical" observations is a slightly different attribute:  nlobs instead of nobs

There is rarely a difference.  NOBS is the total number of observations, which is unaffected by observations that have been interactively marked for deletion but not yet physically removed from the data set.  NLOBS is reduced by the number of observations that have been marked for deletion.  The L in NLOBS is for "Logical".


Trusted Advisor
Posts: 1,300

Re: SAS File I/O Functions

Astounding,

NLOBS is a good recommendation, it aids in situations where as you said, you have deleted records, and also cases where you use the file operation functions to apply where clauses to datasets and other things as well.

☑ This topic is SOLVED.

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

Discussion stats
  • 10 replies
  • 348 views
  • 0 likes
  • 4 in conversation