DATA Step, Macro, Functions and more

Create new variable from existing

Reply
Contributor
Posts: 24

Create new variable from existing

I am trying to create a new variable from an exisitng one, but whenever I try, it says variable uninitialized. What is the problem?

 

libname Iat '\\vmware-host\Shared Folders\Desktop\SAS\IAT\';

 

PROC IMPORT OUT= X.X

            DATAFILE= 'timetoiat'

            DBMS=CSV REPLACE;

     GETNAMES=YES;

GUESSINGROWS=X;

     DATAROW=X; 

 

 

RUN;

 

 

proc import datafile="\\vmware-host\Shared Folders\Desktop\SAS\IAT\timetoiat"

out=Iat.timetoiat dbms=xlsx replace; 

sheet="Sheet1"

getnames=yes; 

 

run;

 

Data iat;

set iat.timetoiat;

IF NIHSS LE 16 THEN NIHSS=NIHSSLT16;

IF NIHSS >=16 THEN NIHSS=NIHSSGTE16;

RUN;

 

log:

20       Data iat;

21       set iat.timetoiat;

22       IF NIHSS LE 16 THEN NIHSS=NIHSSLT16;

23       IF NIHSS >=16 THEN NIHSS=NIHSSGTE16;

24       RUN;

 

NOTE: Variable NIHSSLT16 is uninitialized.

NOTE: Variable NIHSSGTE16 is uninitialized.

NOTE: There were 380 observations read from the data set IAT.TIMETOIAT.

NOTE: The data set WORK.IAT has 380 observations and 24 variables.

NOTE: DATA statement used (Total process time):

      real time           0.03 seconds

      cpu time            0.01 seconds

 

Super User
Posts: 17,959

Re: Create new variable from existing

The error message is pretty clear. 

Run a proc contents to check your variable names are correct. 

Super User
Posts: 5,099

Re: Create new variable from existing

Which variable are you trying to create?  This code is trying to replace NIHISS.  It doesn't create anything new.

Super User
Posts: 6,972

Re: Create new variable from existing

20       Data iat;
21       set iat.timetoiat;
22       IF NIHSS LE 16 THEN NIHSS=NIHSSLT16;
23       IF NIHSS >=16 THEN NIHSS=NIHSSGTE16;
24       RUN;

NOTE: Variable NIHSSLT16 is uninitialized.
NOTE: Variable NIHSSGTE16 is uninitialized.

this simply means that there are no variables NIHSSLT16 and NIHSSGTE16 in dataset iat.timetoiat.

 

Have a look at your infile you use in PROC IMPORT. I also noted that you import into library LAT, but use IAT.timetoiat in your DATA step.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
SAS Employee
Posts: 17

Re: Create new variable from existing

Your previous code is replacing the value of NIHSS but not created variables NIHSSLT16 and NIHSSGTE16, you should have code:

 

Data iat;
  set iat.timetoiat;
   IF NIHSS LE 16 THEN NIHSSLT16=NIHSS;
   IF NIHSS >=16 THEN NIHSSGTE16=NIHSS;
  RUN;

 

 

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