BookmarkSubscribeRSS Feed
khalillx
Fluorite | Level 6

data one;
set project1;
consg = (consumption*42)/Population;
pce0 = PCE/78.23517;
rpgas = Price/pce0;
logrpgas = log(rpgas);
logconsg = log(consg);
logincome = log(income);
logPCE_lag = log(PCE_lag);
logUnemployment = log(Unemployment);
logOneyear = log(Oneyear);
num_mon= month (observation_date);
If num_mon=1 then dumjan=1; else dumjan=0;
If num_mon=2 then dumfeb=1;else dumfeb=0;
If num_mon=3 then dummar=1;else dummar=0;
If num_mon=4 then dumapr=1;else dumapr=0;
If num_mon=5 then dummay=1;else dummay=0;
If num_mon=6 then dumjun=1;else dumjun=0;
If num_mon=7 then dumjul=1;else dumjul=0;
If num_mon=8 then dumaug=1;else dumaug=0;
If num_mon=9 then dumsep=1; else dumsep=0;
If num_mon=10 then dumoct=1; else dumoct=0;
If num_mon=11 then dumnov=1; else dumnov=0;
If num_mon=12 then dumdec=1; else dumdec=0;

 

is this how you take logs of variables and set dummy variables? The reason I ask is because this is the format in sas studios but SAS 9.4 might be different. 

8 REPLIES 8
34reqrwe
Quartz | Level 8

I can't see anything immediatly wrong with it.

I assume you also have a run; statement at the end of the code . 

Are you getting any errors in your logs? 

Is the output as you expect ? 

 

 

khalillx
Fluorite | Level 6
I'm getting errors that say: Invalid argument to function LOG(-0.8) at line 433 column 11. I looked at that line and column and I'm not sure what's wrong with it?
Reeza
Super User

Some clarifications for you, SAS UE is running SAS 9.4 TS1M6 at the moment. This is the same as SAS 9.4. There are some differences between using SAS UE and one on your desktop but it's more related to file paths than any type of functionality about your actual code. 

 

Regarding LOG:

Yeah it turns my values into percent form.

The log function most definitely does not convert a number to a percent, it takes the natural log of a number. Most likely you're getting errors because you can't take the log of a negative, zero or missing value. 

 

LOG Function

Returns the natural (base e) logarithm.

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=lefunctionsref&docsetTarg...

 

 

 

Regarding creating the dummy variables, you could simplify that by using an array, see the examples here, specifically see the example titled "Computing New Variables"

https://stats.idre.ucla.edu/sas/seminars/sas-arrays/

 

When you're having issues with your code, it's helpful if you include the log that shows what errors you're encountering. 

data one;
set project1;
consg = (consumption*42)/Population;
pce0 = PCE/78.23517;
rpgas = Price/pce0;
logrpgas = log(rpgas);
logconsg = log(consg);
logincome = log(income);
logPCE_lag = log(PCE_lag);
logUnemployment = log(Unemployment);
logOneyear = log(Oneyear);
num_mon= month (observation_date);
If num_mon=1 then dumjan=1; else dumjan=0;
If num_mon=2 then dumfeb=1;else dumfeb=0;
If num_mon=3 then dummar=1;else dummar=0;
If num_mon=4 then dumapr=1;else dumapr=0;
If num_mon=5 then dummay=1;else dummay=0;
If num_mon=6 then dumjun=1;else dumjun=0;
If num_mon=7 then dumjul=1;else dumjul=0;
If num_mon=8 then dumaug=1;else dumaug=0;
If num_mon=9 then dumsep=1; else dumsep=0;
If num_mon=10 then dumoct=1; else dumoct=0;
If num_mon=11 then dumnov=1; else dumnov=0;
If num_mon=12 then dumdec=1; else dumdec=0;

 

is this how you take logs of variables and set dummy variables? The reason I ask is because this is the format in sas studios but SAS 9.4 might be different. 

 

 

 

 

ScottBass
Rhodochrosite | Level 12
If num_mon=1 then dumjan=1; else dumjan=0;
If num_mon=2 then dumfeb=1;else dumfeb=0;
If num_mon=3 then dummar=1;else dummar=0;
If num_mon=4 then dumapr=1;else dumapr=0;
If num_mon=5 then dummay=1;else dummay=0;
If num_mon=6 then dumjun=1;else dumjun=0;
If num_mon=7 then dumjul=1;else dumjul=0;
If num_mon=8 then dumaug=1;else dumaug=0;
If num_mon=9 then dumsep=1; else dumsep=0;
If num_mon=10 then dumoct=1; else dumoct=0;
If num_mon=11 then dumnov=1; else dumnov=0;
If num_mon=12 then dumdec=1; else dumdec=0;

A comparison operator returns a boolean result, i.e. false=0, true=1.

 

So the above can be shortened to:

 

dumjan = (num_mon=1);
dumfeb = (num_mon=2);
dummar = (num_mon=3);
dumapr = (num_mon=4);
dummay = (num_mon=5);
dumjun = (num_mon=6);
dumjul = (num_mon=7);
dumaug = (num_mon=8);
dumsep = (num_mon=9);
dumoct = (num_mon=10);
dumnov = (num_mon=11);
dumdec = (num_mon=12);

Which can be further shortened to:

 

array months {12} dumjan dumfeb dummar dumapr dummay dumjun dumjul dumaug dumsep dumoct dumnov dumdec;

do i=1 to 12;  (or do i=1 to dim(months))
   months{i}=(num_mon=i);
end;   

Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 8 replies
  • 1005 views
  • 4 likes
  • 4 in conversation