referring to a field indirectly

Discussions about editing and cleaning data
Forum rules
New release: CSPro 8.0
Post Reply
AriSilva
Posts: 591
Joined: July 22nd, 2016, 3:55 pm

referring to a field indirectly

Post by AriSilva »

Is it possible to change the contents of a variable without knowing its name?
For example I want to change the contents of a variable named SEX.
So I can write
SEX = 2;

Can I write something like:
string varname = "sex";
setContents(varname, 2);

which would do the same as the direct assigning.
Why would I need that?
I have a need to edit some variables according to some user commands. So I thought about having an excel file with three columns:
1. Id
2. variable
3. new_value
Reading this file and for each line in the file apply the change accordingly.
Best
Ari
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: referring to a field indirectly

Post by Gregory Martin »

You can use setvalue: https://www.csprousers.org/help/CSPro/s ... ction.html
setvalue("SEX", 2);
I've used this to do recoding from an Excel file, which sounds like your exact use case.
AriSilva
Posts: 591
Joined: July 22nd, 2016, 3:55 pm

Re: referring to a field indirectly

Post by AriSilva »

Great!
That is exactly what I have in mind!
Best
Ari
Post Reply