Re: how to sort variable by character variable first then numericOn Sat, Apr 26, 2008 at 12:00 PM, Karen <irain168@gmail.com> wrote:
> Hi,
>
> who knows if we can use SAS to sort the variables by character
> variable first and then numeric variable.
>
> Such as:
> The original order is:
> StudentID Score Gender Address
>
> I want to sort it as
>
> StudentID Gender Address Score
>
> Any hint?
>
> Thanks very much!
>
Whatever order of variables, irrespective of the type (string or number),
can be used with BY statement .
Muthia Kachirayan
...
Re: how to sort variable by character variable first then numeric #3Karen,
Assuming that Mark is correct and you want to change the order of your
variables, rather than sort the data, then you could also accomplish it
with a retain statement before your set statement. E.g.,
data sample;
StudentID='A1'; Score=78; Gender='M';
Address='123 Cherry Tree Lane'; output;
StudentID='B2'; Score=79; Gender='F';
Address='456 Cherry Tree Lane'; output;
run;
data want;
retain StudentID Gender Address Score;
set sample;
run;
Art
-------
On Sat, 26 Apr 2008 09:00:23 -0700, Karen <irain168@GMAIL.COM> wrote:
>Hi,
>
>who knows if we can use SAS to sort the variables by character
>variable first and then numeric variable.
>
>Such as:
>The original order is:
>StudentID Score Gender Address
>
>I want to sort it as
>
>StudentID Gender Address Score
>
>Any hint?
>
>Thanks very much!
...
Re: how to sort variable by character variable first then numeric #2Hi Karen,
There are many variations but here are a couple.
data sample;
StudentID='A1'; Score=78; Gender='M';
Address='123 Cherry Tree Lane'; output;
StudentID='B2'; Score=79; Gender='F';
Address='456 Cherry Tree Lane'; output;
run;
We can order the columns specifically, AND
we can order the columns by CHARACTER then NUMERIC.
Below are examples of both.
There are several ways to order the column
in specific order:
* SQL order as you list them ;
proc sql;
create table result1 as
select
StudentID,
Gender,
Address,
Score
from
sample
;
quit;
* datastep compiler order them in ;
* the order they are incurred. ;
* i.e. LENGTH found before SET. ;
data result2;
length StudentID $2
Gender $1
Address $20
Score 8
;
set sample;
run;
Here is one way to order by CHAR then NUM.
* ordering by character then numeric ;
data result3;
set sample(keep=_character_);
set sample(keep=_numeric_);
run;
Hope this is helpful.
Mark Terjeson
Senior Programmer Analyst
Investment Management & Research
Russell Investments
Russell Investments
Global Leaders in Multi-Manager Investing
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Karen
Sent: Saturday, April 26, 2008 9:00 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject:...
variable of variable $$, ${ ...hi,
i m trying to find how to access a variable of variable (which is an image)
i want to know the size of the picture
the name of the picture is photo1
next one is photo2, next one is photo3 ...
for ($i=1;$i<$MAX_PHOTOS;$i++)
{
$photo='photo'.$i;
$$photo_size; //don t work
}
thx
"cdt_sylvestre" <cdtEffacercAsly@relayeur.com> wrote in message
news:3ff934d6$0$17130$626a54ce@news.free.fr...
> hi,
>
> i m trying to find how to access a variable of variable (which is an
image)
> i want to know the size of the picture
> the name of the picture is ...
A variables variableshow can I declare a variable with another variable name?
for example I will use PHP:
$a= "hello";
$a_hello="baybay";
print ${'a_'.$a) //output: baybay
how can i do it with no Arrays using python
thanks!
On Aug 23, 7:25=A0pm, Gandalf <goldn...@gmail.com> wrote:
> how can I declare a variable with another variable =A0name?
>
> for example =A0I will use PHP:
>
> $a=3D "hello";
>
> $a_hello=3D"baybay";
>
> print ${'a_'.$a) =A0//output: baybay
>
> how can i do it with no Arrays using =A0python...
Variable in VariableIs it possible to print the the value of a variable in a variable
what i mean:
Declare @test varchar(255)
Declare @foo varchar(255)
Declare @strSQL varchar(255)
set @test = 'Hallo'
Set @foo = '@test'
Print @foo
Set @strSQL = 'SELECT ' + @foo --Expected result is 'Hallo'
exec master..sp_ExecuteSQL @strSQL
How doess it work?
I hope you understand my problem
Thanks
"Michi Albatross" <alber@netdot.ch> wrote in message
news:67ae724b.0410080410.5c8ccb59@posting.google.com...
> Is it possible to print the the value of a variable in a variable
...
Variable in variable?Hello,
I think that what I'm trying to do is impossible, but before I give up I
thought I'd try and pick a few more knowledgeable brains than my own.
I have any array of user defined type variables. I need to loop through the
array (doing certain calculations) on a particular member variable. I then
want to loop through the array again on a different member variable doing
very similar calculations. I only need to change a couple things in the
loop, otherwise the loop is identical from one member to the other. In a
nutshell, what I'm trying to do is use a variable, that will change its
contents accordingly, that I will use to rename the member within the array.
This seems harder to explain than perhaps showing an example:
ArryName(index).MemberName '----standard syntax for refering to a
varibale within an array of user defined type.
'I declare another variable to hold the changing member name that will
be used on repeating iterations through the same loop (using nested loops)
Dim ChangingMemberName as String
ChangingMemberName = ".MemberName1"
'1st iteration
ArryName(index).ChangingMemberName
'2nd iteration
ChangingMemberName = ".MemberName2"
ArryName(index).ChangingMemberName
This code does not work and only generates errors. It would appear that
trying to rename a member within an array with another variable is not
possible but the efficiencies to be gained are ...
Variable variables?I have a situation which I 'think' I need to use variable variables and
not sure how to go about it.
I have several <select multiple> elements on a search form with their
names created dynamically and the options created dynamically.
$parent holds the name such as "Women", "Mens" etc..
$c_id holds category_id and is sent off as the 'value' of the option.
This form is self calling and an array is created for the multiple
option selected.
Women => array([0]=>20,[1]=>21,...)
Mens => array([0]=>32,[1]=>35,...)
I am using in_array() to check returned posted values against an id.
How do I reference that array by using the value of $parent.
if $parent is 'Women' I need to reference the array 'Women'
Here is a nutshell of the algorithm.
foreach($parent_ary as $parent) {
echo "<select {$parent}[] multiple>";
foreach($category_ary as $c_id=>$category) {
if(in_array($c_id, array of posted value)) {
// Create select option
} else {
// Create regular option
}
}
echo "</select>";
}
I hope this makes sense and yes I did RTM but could not transpose what
they where explaining to what I need to do.
Thanks
Scotty
On 7/25/2013 10:56 PM, Scott Johnson wrote:
> I have a situation which I 'think' I need to use variable variables and
> not sure how to go about it.
>
>
> I have several <s...
VARIABLE (was is VARIABLE does ? )
Charles Melice raises an interesting question when he asks why VARIABLE
is in the CORE wordset. Andrew Haley responded that CORE is not intended
to be a minimalist wordset.
We have in the past had some discussion re: proper selection of a minimal
set of words. Does anyone think there is merit to the suggestion of adding
a minimal-CORE wordset to the revised Standard (whenever that happens)?
The virtue of a Standard minimal word set would be the virtue we have
(albeit with some exceptions) found in having a Standard Forth, namely
virtually painless portability and inter-operability. I, for o...
Variable for a VariableI doubt this is possible, but thought to ask anyway.
I have a situation where there are 30 arrays (of structures) all in one
module. Each representing a separate tool within the application.
Just for examples sake I'll make up a few:
Hammer(iElements)
Saw(iElements)
Screwdriver(iElements)
...
Drill(iElements)
I have this Select Case that checks a Tool_ID and locates the correct tool
to operate on.
Select Case Tool_ID
Case ID_Hammer
Hammer(iElements).visible = false
Case ID_Saw
Saw(iElements)...
Variable into a variableI don't know if I'm saying this right but is it possible to pass a
variable into a variable in matlab?
For example in php you can have a variable named something and by
writting
< $that = 'something'.$number; >
you can use change the variable $number with any number you want and
put for example the variable something1 into $that.
"Iraklis Markelis" <it00139@uom.gr> wrote in message
news:hgs1mrxsczak@legacy...
> I don't know if I'm saying this right but is it possible to pass a
> variable into a variable in matlab?
> For example in ...
Variable in a VariableHi All,
I have a dataset
data abc;
input a b $ c d;
datalines;
100 c 20 30
200 d 10 40
300 c 23 99
;
in this dataset variable b contains either c or d(other variable
name)
how can i get the value of c or d i.e 20 or 30 from first
observation....
Please let me know
thanks in advance
On Feb 8, 1:32 pm, "sasguy" <addanki...@gmail.com> wrote:
> Hi All,
> I have a dataset
> data abc;
> input a b $ c d;
> datalines;
> 100 c 20 30
> 200 d 10 40
> 300 c 23 99
> ;
> in this dataset variable b contains either c or d(other variable
> name)
> how can...
Variable VariableHi List, is there in python a variable variable like in PHP ($$var)?
What I want to do is something like that:
pc=["a","b","c"]
for i in pc:
i = anyclass()
a.shutdown()
b.update()
Any Ideas?
Many Thanks, m
Tanteauguri wrote:
> Hi List, is there in python a variable variable like in PHP ($$var)?
>
> What I want to do is something like that:
>
> pc=["a","b","c"]
>
> for i in pc:
> i = anyclass()
>
> a.shutdown()
> b.update()
Use a dictionary:
stuff = {}
pc = ['a', 'b', ...
how to change the character variable to numerical variable?Hi,
I am trying to use the function
num_variable=input(char_variable,BEST12.) to change the variable type
from char to num. How to do that in the program?
Thanks so much!
...
Assign variables to a new variable based on variable names in SASThank so much Nagakumar Sridhar and Fehd, Ronald J. for answering my
previous
question. However I was not clear in the original post. I modified my
phrasing
and the new version is below:
I have met the following problem and I need your expert help.
The variable names in the data set looks like this:
a_1995q3 a_1995q4 a_1997q1 ........... a_2003q4 n
Please note that "quarter" numbers in "a_****q*" variables may not be
continuous, i.e. there might be a missing quarter.
and n can have the value of any quarter for while a_quarter exists,
say
"1995q3", "...
Re: how to change the character variable to numerical variable?You just need a data step and fill in using variable names that apply
to your data.
data test;
a = '123.4';
b = input(a,8.);
run;
proc contents;
run;
Keep in mind that you have to create a "new" numeric variable. That
is you cannot "convert" A in the example above to numeric.
On Sun, Mar 2, 2008 at 12:28 AM, irenelj23@gmail.com
<irenelj23@gmail.com> wrote:
> Hi,
> I am trying to use the function
> num_variable=input(char_variable,BEST12.) to change the variable type
> from char to num. How to do that in the program?
> Thanks so much!
>
Thanks so much!
There is a variable in dataset1 in the exercise library. I tried to
change the type of one of the variables-ID from character to
numerical. Is this the right way to do?
I first created a new variable id_num and then dropped the old
variable ID which is character, then I changed the name of the
numerical id_num to the original name ID.
data exercise.dataset1;
set exercise.dataset1;
id_num=input(ID,best12.);
drop sampid;
rename sampid_num=sampid;
Thanks for your help!
...
code to convert a character variable to numeric variable withI have been struggling with this code that keeps giving me a nasty warning message that says "it cannot perform mathematical operation blah blah blah"? when I think I have followed all the syntax rules on coding a SAS program.
Here's the picture:
input variable is HRMIN $5, and the value of HRMIN variable looks like this 11:45.
my client wants this output as?a numeric variable called ?OUTHRMIN with?time5. format.
my code?within my datastep is:? OUTHRMIN = input(HRMIN,time5.);
and I get these error (actually, note:)?messages:
NOTE: Invalid argument to function INPUT at line 1327 column 20.
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to
missing values.
Each place is given by: (Number of times) at (Line):(Column).
2 at 1327:20
Could someone see any glaring error in my code?
??
lost in TIME,
Meenit
________________________________________________________________________
More new features than ever. Check out the new AOL Mail ! - http://webmail.aol.com
...
Re: How to transfer character variables into numeric variables byChiu-Chen,
There is no way easy way to get SAS to do what you want. The problem will
coms in since you have some vars that are true character variables, some
that are true numerics held as characters, and here is the problem some that
are a mixture of character and numeric and right fully held as character.
If I understand you correctly you have all vars as character. Thus any mass
indescriminant conversion will give you errors in your log and not a good
error at that.
To do what you want all you need is a few simple things, first a list of the
numeric variables held as text that you want converted to numeric, second a
rename statement, length statement,, a drop statement on th eoutput side of
things, and lastly an assignment statement.
data one ;
infile cards dsd dlm = ' ' ;
input x1 $ x2 $ x3 $ x4 $ ;
cards ;
A 1 1 1
B 2 B 2
C 3 C 3
D 4 4 4
;
run ;
data two (drop = _:) ;
length x2 x4 8. ;
set one (rename = (x2 = _x2 x4 = _x4)) ;
x2 = _x2 ;
x4 = _x4 ;
run ;
proc contents ;
run ;
Now if you have a lot of vars you need converted this process can be made
easier by the use of either macros and/or arays.
Toby Dunn
From: "subscribe sas-L Chen, Chiu-Chen" <angelina.aml@YAHOO.COM.TW>
Reply-To: "subscribe sas-L Chen, Chiu-Chen" <angelina.aml@YAHOO.COM.TW>
To: SAS-L@LISTSERV.UGA.EDU
Subject: How to transfer character variables into numeric variables by
using DO LOOP�H
Date: Sun, 24 Jul 2005 04:57:04 -0400
I have some...
Re: How to transfer character variables into numeric variables by #3Hi Chen,
I have a macro that does that, while "preserving" original variable names
and attributes like labels. You can specify more than one variable at a
time, while you may also specify no-numeric values and their corresponding
new numeric values to be replaced by.
See:http://home.hccnet.nl/jim.groeneveld/software/SASmacro/aRecodeN.zip
and in the ZIP file the .SAS macro.
Regards - Jim.
--
Y. (Jim) Groeneveld, MSc., Biostatistician, Vitatron b.v., NL
Jim.Groeneveld_AT_Vitatron.com (replace _AT_ by AT sign)
http://www.vitatron.com, http://home.hccnet.nl/jim.groeneveld
My computer always teaches me something new I thought I knew already.
[common disclaimer]
On Sun, 24 Jul 2005 04:57:04 -0400, subscribe sas-L Chen, Chiu-Chen
<angelina.aml@YAHOO.COM.TW> wrote:
>I have some mixed columns in an Excel data. So I read all variables into
>SAS as character variables. Now I want to transfer all character variables
>to numerical variables, but how should I write the program�HI wrote the
>following program, but it doesn't work. Can anybody tell me where is wrong
>or how to write correctly�H
>
> data chen;
> set chen;
> array XXX[*] _character_;
> do kk=1 to DIM(XXX);
> XXX[kk]=input(XXX[kk],1.);
> end;
> run;
>
>
>Thanks~~
...
Re: How to transfer character variables into numeric variables by #2Would the following do what you want?
data chen;
input a $ b $ c $;
cards;
1 2 3
a 4 5
6 b 7
8 c d
;
run;
data chen;
set chen;
array XXX[*] _character_;
array YYY[3];
do kk=1 to DIM(XXX);
YYY[kk]=input(XXX[kk],1.);
end;
run;
Art
---------
On Sun, 24 Jul 2005 04:57:04 -0400, subscribe sas-L Chen, Chiu-Chen
<angelina.aml@YAHOO.COM.TW> wrote:
>I have some mixed columns in an Excel data. So I read all variables into
>SAS as character variables. Now I want to transfer all character variables
>to numerical variables, but how should I write the program�HI wrote the
>following program, but it doesn't work. Can anybody tell me where is wrong
>or how to write correctly�H
>
> data chen;
> set chen;
> array XXX[*] _character_;
> do kk=1 to DIM(XXX);
> XXX[kk]=input(XXX[kk],1.);
> end;
> run;
...
Re: code to convert a character variable to numeric variableMeenit,
Is it possible you have missing values for HRMIN? I ask because it
seems the note only applies to 2 observations.
Jack Clark
Research Analyst
Center for Health Program Development and Management
University of Maryland, Baltimore County
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
meenit@AOL.COM
Sent: Friday, December 14, 2007 1:29 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: code to convert a character variable to numeric variable with
SAS time5. format.
I have been struggling with this code that keeps giving me a nasty
warning message that says "it cannot perform mathematical operation blah
blah blah"? when I think I have followed all the syntax rules on coding
a SAS program.
Here's the picture:
input variable is HRMIN $5, and the value of HRMIN variable looks like
this 11:45.
my client wants this output as?a numeric variable called ?OUTHRMIN
with?time5. format.
my code?within my datastep is:? OUTHRMIN = input(HRMIN,time5.);
and I get these error (actually, note:)?messages:
NOTE: Invalid argument to function INPUT at line 1327 column 20.
NOTE: Mathematical operations could not be performed at the following
places. The results of the operations have been set to
missing values.
Each place is given by: (Number of times) at (Line):(Column).
2 at 1327:20
Could someone see any glaring error in my code?
??
lost in TIME,
Meenit
_______________________________________________________________________...
Re: transfer character variable to numeric variable( date)Well, it's not a date. There is no Feb 31st. On up to 29th on leap year.
On 4/13/06, Mindy <master2005_sas@yahoo.com> wrote:
>
> Hey, guys,
>
> I have a question regarding how to transfer a character variable to SAS
> date variable.
>
> The detail is I have a SAS data set TRY, which including a character
> variable A such as "20050231", how can I transfer A to numeric
> variable, which correspondences to Feb31, 2005. The reason of doing
> this transfer is that I need to calculate the difference of this
> variable with another date variable.
>
> I try to use realdate=3Dinput(c_date, yymmdd8.); , but get error message.
>
> Thanks a lot !
>
> Mindy
>
--
PharmaLogic, LLC
484.919.4925
PharmaLogic.LLC@gmail.com
...
Re: how to change the character variable to numerical variable? #2Irene,
I think you are trying to do the following:
libname exercise "k:\art";
data exercise.dataset1;
input sampid $;
cards;
1 1
2 2
3 3
;
data exercise.dataset1;
set exercise.dataset1;
sampid_num=input(sampid,best12.);
drop sampid;
rename sampid_num=sampid;
run;
However, I'd strongly recommend NOT overwriting your original dataset!
Art
----------
On Sun, 2 Mar 2008 07:50:51 -0800, irenelj23@gmail.com
<irenelj23@GMAIL.COM> wrote:
>There is a variable in dataset1 in the exercise library. I tried to
>change the type of one of the variables-ID from character to
>numerical. Is this the right way to do?
>I first created a new variable id_num and then dropped the old
>variable ID which is character, then I changed the name of the
>numerical id_num to the original name ID.
>
>data exercise.dataset1;
>set exercise.dataset1;
>id_num=input(ID,best12.);
>drop sampid;
>rename sampid_num=sampid;
>
>Thanks for your help!
...
Split Character Variable into VariablesHi Listers,
I made some research but I didn't find how could split a character
variable that has a text that represents multiple answers, like this:
VAR
abbcd
And I want to create other variables like this:
VAR1 VAR2 VAR3 VAR4 VAR5
a b b c d
Thanks in advance,
Marcio
...