BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
InfoAlisaA
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
FriedEgg
SAS Employee

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

10 REPLIES 10
FriedEgg
SAS Employee

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;

InfoAlisaA
Calcite | Level 5

Thanks FriedEgg! Smiley Happy This was very helpful!

Nice to get help from another Coloradan! Smiley Happy

Cheers!

Alisa

FriedEgg
SAS Employee

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.

Linlin
Lapis Lazuli | Level 10

Hi FE,

Does your company allow working remotely?  Thank you!

FriedEgg
SAS Employee

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...

Linlin
Lapis Lazuli | Level 10

Thank you!!!  -Linlin

InfoAlisaA
Calcite | Level 5

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

FriedEgg
SAS Employee

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

Astounding
PROC Star

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".


FriedEgg
SAS Employee

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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