Hello,
I am trying to read a specific value in variable and use it to divide the rest of the values to find a new value. Here's my variable list:
Price
3.85
5.1
22
3.95
6.3
40
3.3
3211
30
6.35
55
39.2
So I have to read the first value i.e. 3.85
and create a new variable Pur_power
data_null_
set econs;
pur_power = price/ read value (3.85) - unable to do this
Can please someone help me with this?
Thanks,
S
data ppd;
if _n_ eq 1 then set economist(keep=local_mc rename=(local_mc=first_local_mc)); *(to read the first value in variable local_Mc);
set work.economist;
PPD = divide(local_Mc,first_local_Mc); *(divide each value in local_Mc and create a new variable PPD);
valuation=((PPD-xchangrt)/xchangrt)*100;
run;
Please clarify your post highlighting what you have, what you want and what you've done so far, if you have code.
What I have: Below dataset (line 5)
What I have done so far: the code is mentioned
What I want to do: create a new variable PPD and calculate the value using the formula below (line 9)
1. data economist;
2. infile datalines;
3. input country$:15. currency$ local_Mc xchangrt;
4. datalines;
5. United_States US$ 2.65 1
Argentina Peso 3.85 2.9931
Australia A$ 3.2 1.2979
Brazil Real 4.5 2.934
Britain £ 1.99 0.5424
Canada C$ 3.2 1.3286
China Yuan 9.95 8.2873
Euro_area € 2.75 0.7921
Hong_Kong HK$ 11.25 7.7741
Hungary Forint 492 210.83
Indonesia Rupiah 16155 8458
Japan ¥ 263 105.74
Malaysia M$ 5.1 3.7916
Mexico Peso 22 11.186
New_Zealand NZ$ 3.95 1.4415
Poland Zloty 6.3 3.8447
Russia Rouble 40 28.54
Singapore s$ 3.3 1.6853
South_Africa Rand 14.05 7.0302
South_Korea Won 3211 1174.4
Sweden SKr 30 7.23
Switzerland SFr 6.35 1.2416
Taiwan NT$ 70.55 33.22
Thailand Baht 55 39.232
;
6. run;
7. data _null_;
8.set work.economist;
9. PPD = local_Mc/ first.local.Mc; *(to read the first value in variable local_Mc and divide each value in local_Mc and create a new variable PPD/;
valuation=((PPD-xchangrt)/xchangrt)*100
run;
*Error - first.local.Mc not initialized;
Hope this clarfies.
data ppd;
if _n_ eq 1 then set economist(keep=local_mc rename=(local_mc=first_local_mc)); *(to read the first value in variable local_Mc);
set work.economist;
PPD = divide(local_Mc,first_local_Mc); *(divide each value in local_Mc and create a new variable PPD);
valuation=((PPD-xchangrt)/xchangrt)*100;
run;
Thank you so much!!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.