BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Same answer as via private message. Read the log. 

It works, your PROC PRINT is wrong. The VAR statement does not support formats and the error pretty much tells you that. 

ALWAYS READ THE LOG.

 


@shaher wrote:
data aaa;
input vartype $char9. stat1 stat2;
datalines;
numeric 25.5 12.7
character 36 34.4
numeric 150 124
charecter 23 12.1
;
run;
proc print data=HW4q2; run;
data bbb;
set aaa;
length newvar $ 20;

if vartype ='numeric' then newvar = catt(stat1, ' (' , stat2, ')' );

else newvar = catt(stat1, ' (', stat2, '%)' );

run;
proc print data=bbb;
var vartype $char9. newvar $ 20;
run;

this is the full code

 

View solution in original post

11 REPLIES 11
Reeza
Super User

What's the question for us?

What have you tried? What works, what doesn't?



To answer your question I'd have to type out the data, at minimum, providing that would be helpful for anyone who did want to help you out with this question. Don't post data or code as images.

 

 


@shaher wrote:

1111.JPG11111.JPG


 

shaher
Fluorite | Level 6

Hi 

I'm trying to find a code to create a new character variable.  by using trim function.

PGStats
Opal | Level 21

A character variable named myVar is created as soon as you say

 

myVar = "Some string";

 

 

PG
Reeza
Super User

I'm going to echo the suggestion that the source of this question may be not the most reliable. 


Are you doing an exercise to learn to create new variables or how to create clinical reports?

If it's the latter, I recommend following Cynthia Zenders' Create Complex Reports document and the code that goes along with it. You can work through the examples and then decide how to create your reports.

Astounding
PROC Star

You have numeric values that need to be converted to character, to make them part of the new variable.  As a result, it's easier to forget about TRIM and use CATT instead:

 

length newvar $ 20;

if datatype='numeric' then newvar = catt(stat1, ' (' , stat2, ')' );

else newvar = catt(stat1, ' (', stat2, '%)' );

shaher
Fluorite | Level 6

I use it but not working 

length newvar $ 20;

if vartype ='numeric' then newvar = catt(stat1, ' (' , stat2, ')' );

else newvar = catt(stat1, ' (', stat2, '%)' );

run;
proc print data=HW4q2p1;
var vartype $char9. newvar $ 20;
run;

-----------------

The SAS System 17:54 Tuesday, September 18, 2018 6

Obs vartype stat1 stat2

1 numeric 25.5 12.7
2 character 36.0 34.4
3 numeric 150.0 124.0
4 charecter 23.0 12.1

 

 

this is my friend result but I don't how to get it 

file-1 (1).jpeg

Reeza
Super User

Is that your full code? Where's the DATA step statement?

Paste the full code. The code suggested would need to be embedded within a data step.

 

 


@shaher wrote:

I use it but not working 

length newvar $ 20;

if vartype ='numeric' then newvar = catt(stat1, ' (' , stat2, ')' );

else newvar = catt(stat1, ' (', stat2, '%)' );

run;
proc print data=HW4q2p1;
var vartype $char9. newvar $ 20;
run;

-----------------

The SAS System 17:54 Tuesday, September 18, 2018 6

Obs vartype stat1 stat2

1 numeric 25.5 12.7
2 character 36.0 34.4
3 numeric 150.0 124.0
4 charecter 23.0 12.1

 

 

this is my friend result but I don't how to get it 

file-1 (1).jpeg


 

shaher
Fluorite | Level 6
data aaa;
input vartype $char9. stat1 stat2;
datalines;
numeric 25.5 12.7
character 36 34.4
numeric 150 124
charecter 23 12.1
;
run;
proc print data=HW4q2; run;
data bbb;
set aaa;
length newvar $ 20;

if vartype ='numeric' then newvar = catt(stat1, ' (' , stat2, ')' );

else newvar = catt(stat1, ' (', stat2, '%)' );

run;
proc print data=bbb;
var vartype $char9. newvar $ 20;
run;

this is the full code
Reeza
Super User

Same answer as via private message. Read the log. 

It works, your PROC PRINT is wrong. The VAR statement does not support formats and the error pretty much tells you that. 

ALWAYS READ THE LOG.

 


@shaher wrote:
data aaa;
input vartype $char9. stat1 stat2;
datalines;
numeric 25.5 12.7
character 36 34.4
numeric 150 124
charecter 23 12.1
;
run;
proc print data=HW4q2; run;
data bbb;
set aaa;
length newvar $ 20;

if vartype ='numeric' then newvar = catt(stat1, ' (' , stat2, ')' );

else newvar = catt(stat1, ' (', stat2, '%)' );

run;
proc print data=bbb;
var vartype $char9. newvar $ 20;
run;

this is the full code

 

Reeza
Super User
You should mark someone else's answer as correct, someone who helped with the actual code.
ballardw
Super User

Considering that the vartype is misspelled for the 4th record I would be very careful using their example data.

 

Also anytime a variable changes meanings like that, stat1 is sometimes mean and sometimes count, then someone is providing poor data models to follow...

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 1486 views
  • 3 likes
  • 5 in conversation