Learning SAS? Welcome to the exclusive online community for all SAS learners.

Unable to use CDC code to calculate BMI percentiles in SAS Studio

Reply
New Contributor
Posts: 2

Unable to use CDC code to calculate BMI percentiles in SAS Studio

I am trying to use the CDC NHANES datasets to calculate BMI percentiles for each of the children in the NHANES dataset. The guidelines for doing that are pretty simple, you just need to have all the variables named. I have never had trouble doing this in SAS 9.3, but SAS university is giving me trouble when I try and input the final statement:\

libname refdir "C:\Users\Twarog\Desktop\CDCref_d.sas7bdat";

My error that i get is

ERROR: Library REFDIR is not in a valid format for access method RANDOM.

ERROR: Error in the LIBNAME statement.

Any idea why this is? I put in my sas codes below in case anyone wanted to see them.

data mydata;

    set mydata;

    %include "C:\Users\twarogj\Desktop\cdc-source-code.sas";

run;

data demo_1;

    set NH.demo_d (keep=seqn sddsrvyr ridstatr INDFMPIR sdmvpsu sdmvstra

        WTINT2YR wtmec2yr riagendr ridagemn ridageyr ridreth1)

        NH.demo_e (keep=seqn sddsrvyr ridstatr INDFMPIR sdmvpsu sdmvstra

        WTINT2YR wtmec2yr riagendr ridagemn ridageyr ridreth1)

        NH.demo_f (keep=seqn sddsrvyr ridstatr INDFMPIR sdmvpsu sdmvstra

        WTINT2YR wtmec2yr riagendr ridagemn ridageyr ridreth1);

data demo_2;

    set NH.demo_g (keep=seqn sddsrvyr ridstatr INDFMPIR sdmvpsu sdmvstra

        WTINT2YR wtmec2yr riagendr RIDEXAGM ridageyr ridreth1);

    rename ridexagm=ridagemn;

data bmx_;

    set NH.bmx_d (keep=seqn bmxbmi bmxht bmxwt bmxhead) NH.bmx_e (keep=seqn

        bmxbmi bmxht bmxwt bmxhead) NH.bmx_f (keep=seqn bmxbmi bmxht bmxwt

        bmxhead) NH.bmx_g (keep=seqn bmxbmi bmxht bmxwt bmxhead);

data smqFAM_;

    set NH.smqfam_d (keep=seqn SMD410) NH.smqfam_e (keep=seqn SMD410) NH.smqfam_f (keep=seqn SMD410) NH.smqfam_g (keep=seqn

        SMD410);

       

data SMQRTU_;

    set NH.SMQRTU_d (keep=seqn SMQ680) NH.SMQRTU_e (keep=seqn SMQ680) NH.SMQRTU_f (keep=seqn SMQ680) NH.SMQRTU_g (keep=seqn

        SMQ680);

  

run;

************************************************************************

* Program:  C:\NHANES\AppendMerge_MergeData.sas                       *

* Proposal: Merge NHANES Data                                         *                                           

        ***********************************************************************;

libname nh "C:\Users\jt05452.AD\Desktop\Finished DR Notification";

options ls=72;

proc sort data=work.DEMO_1;

    by SEQN;

proc sort data=work.demo_2;

    by seqn;

proc sort data=work.BMX_;

    by SEQN;

proc sort data=work.hsq_;

    by SEQN;

run;

data mydata;

    merge work.DEMO_1 work.demo_2 work.BMX_ work.smqfam_ work.SMQRTU_ ;

    by SEQN;

run;

data mydata;

    set mydata;

    rename ridagemn=agemos;

run;

data mydata;

    set mydata;

    rename riagendr=sex;

run;

data mydata;

    set mydata;

    rename bmxbmi=bmi;

run;

data mydata;

    set mydata;

    rename bmxht=height;

run;

data mydata;

    set mydata;

    rename bmxwt=weight;

run;

data mydata;

    set mydata;

    rename bmxhead=headcir;

run;

proc contents data=_CDCDATA varnum;

proc means data=_CDCDATA Nmiss min max maxdec=2;

run;

libname refdir "C:\Users\jt05452.AD\Desktop\NHAnes";

data mydata;

    set mydata;

data mydata;

    set mydata;

    if ridageyr >19 then

        delete;

run;

libname refdir "C:\Users\Twarog\Desktop\CDCref_d.sas7bdat";

data mydata;

    set mydata;

    %include "C:\Users\twarogj\Desktop\cdc-source-code.sas";

run;

SAS Super FREQ
Posts: 388

Re: Unable to use CDC code to calculate BMI percentiles in SAS Studio

Hi! Unless I'm misunderstanding, you are having a problem assigning a libname in SAS Studio with University Edition.

When you assign your libname, you need to reference the location as displayed in the properties for the folder.

libname.PNG

For example, if I right-click on "My Folders->data" and get the properties on it, I can see that the location is listed as "/folders/myfolders/data". Thus, my libname statement would be:

libname mydata "/folders/myfolders/data";

This will work. You wouldn't refer to the path as "C:\..." because SAS Studio runs in a Linux VM and wouldn't have visibility into that folder referenced by its Windows name.

Give it a try!

Super User
Posts: 11,343

Re: Unable to use CDC code to calculate BMI percentiles in SAS Studio

Posted in reply to RandyMullis

And similar with the %include statement path to the code file.

New Contributor
Posts: 2

Re: Unable to use CDC code to calculate BMI percentiles in SAS Studio

Posted in reply to RandyMullis

Still having trouble and getting the same comment

LIBNAME refdir '/folders/myfolders/final/cdcref_d.sas7bdat';

data mydata; set SET2;

%include '/folders/myfolders/final/cdc-source-code.sas';

proc means data=_cdcdata; run;

it is saying that refdir.cdcref_d doesn't exist, which is wrong

SAS Super FREQ
Posts: 388

Re: Unable to use CDC code to calculate BMI percentiles in SAS Studio

The library (e.g. libname) refers to the directory where the data is located.

I think you'd want

LIBNAME refdir '/folders/myfolders/final';

proc means data=refdir.cdcref_d;

or something similar depending on what exactly you are doing. (The library contains the data and you refer to the data by referencing the library then the dataset with a period (.) between them. This is the general approach but there are other aspects.)

This and similar topics might be helpful:

How do I access data in SAS?

Randy

Valued Guide
Posts: 765

Re: Unable to use CDC code to calculate BMI percentiles in SAS Studio

Hi ... not an answer to your question but I'm just curious.  Why six passes through a data set to rename six variables ...

data mydata;

    set mydata;

    rename ridagemn=agemos;

run;

data mydata;

    set mydata;

    rename riagendr=sex;

run;

data mydata;

    set mydata;

    rename bmxbmi=bmi;

run;

data mydata;

    set mydata;

    rename bmxht=height;

run;

data mydata;

    set mydata;

    rename bmxwt=weight;

run;

data mydata;

    set mydata;

    rename bmxhead=headcir;

run;

How about one use of PROC DATASETS ...

proc datasets lib=work nolist;

modify mydata;

rename ridagemn=agemos riagendr=sex bmxbmi=bmi bmxht=height bmxwt=weight bmxhead=headcir;

quit;

Ask a Question
Discussion stats
  • 5 replies
  • 714 views
  • 0 likes
  • 4 in conversation