Learning SAS? Welcome to the exclusive online community for all SAS learners.

How should I use the same variable assigning different values

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

How should I use the same variable assigning different values

Hi,

I am working on a large data set and I need to assign the age variable into two categories . I need to perform some calculations on the category of people under 50 or above 50 and then scale wise 0-29,30-39 etc.

When I run the code for the first case i.e people under 50 or above 50 and I set the value senior for agepr (it already exists on the data set) , it works as It is supposed to but in the second case i.e 0-29,30-39 etc , I set the value fpre for agepr and hit run , it gives me an error

Variable fpre doesn't exist.

I am not able to figure out how to use the same variable assigning different values

here is the code :

proc format;

value senior

low-<50='moins de 50 ans'

50-high='50 ans et plus';

run;

proc freq;

table senior;

format agepr senior.;

weight pondmen;

run;

proc format;

value fpre

low-29='moins de 29ans'

30-39='30 à 39ans'

40-49='40 à 49ans'

50-59='50 à 59ans'

60-69='60 à 69ans'

70-79='70 à 79ans'

80-high='plus de 80ans';

run;

proc freq;

table fpre;

format agepr fpre.;

run;


Accepted Solutions
Solution
‎11-08-2014 06:28 PM
Trusted Advisor
Posts: 1,204

Re: How should I use the same variable assigning different values

fpre. is a format and you need to associate this format with variable agepr. Please try this.

proc freq;

table cs42*agepr;

format agepr fpre.;

weight pondmen;

run;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,204

Re: How should I use the same variable assigning different values

proc freq;

table agepr;

format agepr fpre.;

run;

Occasional Contributor
Posts: 7

Re: How should I use the same variable assigning different values

Thank you very much for your help.


it works in the other case but if I try to see what are the respective professions according to the age scale. it gives me an error : fpre doesn't exist. and If I write agepr instead of fpre , it shows a table stating the professions from the age 17 to 101 . my aim is to get the professions scale wise.

data c;

set c;

if cs42pr in ('11','12','13', '21', '22','23','71','72') then cs42='agriculteurs, artisants, commerçants';

else if cs42pr in ('31','33','34','35','37','38','74') then cs42='professions libérales, cadres';

else if cs42pr in ('42','43','44','45','46','47','48','75') then cs42='professions intermédiaires';

else if cs42pr in ('52','53','54','55','56','77') then cs42='employés';

else if cs42pr in ('62','63','64','65','67','68','69','78') then cs42='ouvriers';

else cs42='autres';

run;

proc freq;

table cs42*fpre;

weight pondmen;

run;

Solution
‎11-08-2014 06:28 PM
Trusted Advisor
Posts: 1,204

Re: How should I use the same variable assigning different values

fpre. is a format and you need to associate this format with variable agepr. Please try this.

proc freq;

table cs42*agepr;

format agepr fpre.;

weight pondmen;

run;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 319 views
  • 3 likes
  • 2 in conversation