BookmarkSubscribeRSS Feed
bharathtuppad
Obsidian | Level 7

Data a;

input start label $9.;

fmtname="$abc";

cards;

101 bangalore

102 mangalore

103 mysore

104 bellary

105 davangere

;

proc format cntlin=a;

run;

data b;

input xyz;

format xyz $abc.;

cards;

101

102

104

108

;

proc print;

run;

In the above program, the format gets applied on the numeric variable. But when i create a numeric format and apply it on character variable, it will not work. can somebody explain to me this.

Thanks in advance.

Bharath.

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I am not sure I full yunderstand your question.  the code you have posted fails to run, as it should.  Character formats, those ones with name starting $ can only be applied to character data, those formats without the dollar can only be assigned to numeric variables.  Now in your example, the first dataset is reading the variable START in as a numeric, hence in the format step it is setting the format as numeric.  In your second datastep you are also reading xyz in as numeric.  If you change both input statements to :

input start $ label $9.;

and

input xyz $;


Then the code will run.

bharathtuppad
Obsidian | Level 7

I understood why the program was runnnig in my session. I had a numeric as well as character format with the same name. Instead of applying character format, SAS was applying numeric format i guess.

bharathtuppad
Obsidian | Level 7

The format that got created here (abc) will be a character format.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 680 views
  • 0 likes
  • 2 in conversation