Suppose I have this following table
Here Name is character variable and rest of the two (Value1 and Value2) are numeric variable. I have one condition where Value1 is "Ult" then value2 should be "Ult" also, else the value of Value2 will be as it is... Can anyone give me one quick solution?.. Very urgent.. Regards Sourav
If you want tested code as answer then you should post the sample data as a working data step creating such data.
As for your question something as below should do (not tested as no data provided):
if value1='Ult' then value2=value1;
@Sourav_sas wrote:
Suppose I have this following table
Here Name is character variable and rest of the two (Value1 and Value2) are numeric variable. I have one condition where Value1 is "Ult" then value2 should be "Ult" also, else the value of Value2 will be as it is... Can anyone give me one quick solution?.. Very urgent.. Regards Sourav
Can't be. 'Ult' and 'Valt' are strings, and the values are left-aligned, which is the norm for character variables.
Please post example data in a data step with datalines, setting the correct types and formats.
Or use the macro provided in https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... to convert your dataset to a data step.
Hi Kurt
Thank for your reply. I know the situation is kind of this right now. But there may be some way, I can fulfill the condition as I mentioned, or I can not do this?
Regards
Sourav
Since value2 is numeric, you can't set it to a character value.
I got your point. If the table looks like the above table, and only for Value1 Ult we need Value2 Ult, rest of the Value2 will be same, then what would we follow, can suggest me for that?
Regards
Sourav
That's a simple if - then statement, very easy to do. You won't need help with that.
If you want tested code as answer then you should post the sample data as a working data step creating such data.
As for your question something as below should do (not tested as no data provided):
if value1='Ult' then value2=value1;
@Patrick wrote:If you want tested code as answer then you should post the sample data as a working data step creating such data.
As for your question something as below should do (not tested as no data provided):
if value1='Ult' then value2=value1;
I know this is very easy code, but my concern is in there from numeric to character,
I am using the following sample code.
Data Upload;
Input Name $ 1-2 Value1 $ 3-7 Value2;
Input (Value2, $4.);
Datalines;
A Ult 1
B Valt 3
C Ult 2
D Valt 5
;
Run;
Data Upload3;
Set Upload;
Value5 = Put (Value2, 1.);
Value6 = Input (Value5, $1.);
Drop Value2 Value5;
Run;
Data Upload2;
Set Upload;
If Value1 = 'Ult' then Value6 = Value1;
Run;
Here I can convert the numeric to character value. In the last data step some how I am losing the value. The output is looking like as following screenshot.
I know this is very easy solution. Can I have that? As I am not able to do that.
You only set value6 when the condition is met, in other cases it stays missing. Add an "else" branch to your if statement that deals with those other cases.
Thanks guys for your help,,,,,, I am using this sort of sample code now, I am getting my output as expected....
Data Upload;
Input Name $ 1-2 Value1 $ 3-7 Value2;
Datalines;
A Ult 1
B Valt 3
C Ult 2
D Valt 5
;
Run;
Data Upload;
Set Upload;
Value5 = Put (Value2, 5. -l);
Value6 = Input (Value5, $10.);
If Value1 = 'Ult' then Value6 = Value1;
Else Value6 = Value5;
Drop Value2 Value5;
Run;
Output looks like....
Thank you, thanks a lot for your support...
Regards
Sourav
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 16. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: