Reading a value in a variable

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Reading a value in a variable

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


Accepted Solutions
Solution
‎02-22-2017 06:59 AM
Respected Advisor
Posts: 3,799

Re: Reading a value in a variable

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;

View solution in original post


All Replies
Super User
Posts: 19,870

Re: Reading a value in a variable

Please clarify your post highlighting what you have, what you want and what you've done so far, if you have code. 

New Contributor
Posts: 3

Re: Reading a value in a variable

[ Edited ]

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. 

 

Solution
‎02-22-2017 06:59 AM
Respected Advisor
Posts: 3,799

Re: Reading a value in a variable

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;
New Contributor
Posts: 3

Re: Reading a value in a variable

Posted in reply to data_null__

Thank you so much!!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 143 views
  • 2 likes
  • 3 in conversation