BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Nupur20
Calcite | Level 5

Hi,

I need help with making multiple files from my dataset. This is how the dataset looks like:

Community Name               Time                  Values

CommunityA                       June                    56

CommunityB                       May                     94

CommunityC                       April                     54

CommunityD                      December             10

and so on....

I want to make separate files for each community with thier name identified in the file and rest of the communitites will be blinded.

For eg: Using the dataset above, I want to make 4 different files for each community like this:

For communityA:

Community Name               Time                  Values

CommunityA                      June                    56

2                                       May                     94

3                                        April                     54

4                                        December             10

The file for communityA will have data for the rest of the communities except the community name is blinded and replaced by 2,3,4.

Similarly the file for CommunityB will look like,

Community Name               Time                  Values

1                                         June                    56

CommunityB                        May                     94

3                                        April                     54

4                                        December             10

and so on...

Is this possible in SAS? I would greatly appreciate your time and help regarding the same.

1 ACCEPTED SOLUTION

Accepted Solutions
UrvishShah
Fluorite | Level 6

Hi,

Try the following code in addition of Proc Format.....

data commA commB commC commD;

      set test;

      if community_name EQ "communityA" then output commA;

      if community_name NE "communityA" then do;

         community_name = _N_;

         output commA;

      end;

      if community_name EQ "communityB" then output commB;

      if community_name NE "communityB" then do;

         community_name = _N_;

         if _N_ = '2' then community_name = "communityB";

         output commB;

     end;

      if community_name EQ "communityC" then output commC;

      if community_name NE "communityC" then do;

         community_name = _N_;

         if _N_ = '3' then community_name = "communityC";

         output commC;

     end;

      if community_name EQ "communityD" then output commD;

      if community_name NE "communityD" then do;

         community_name = _N_;

         if _N_ = '4' then community_name = "communityD";

         output commD;

     end;

run;

If there is many community (say more than 50) then process the same logic with iterative %DO loop within Macro Definition...

Cheers

View solution in original post

4 REPLIES 4
ballardw
Super User

How about a solution that doesn't involve any new data? You could use custome formats to accomplish the same thing for most analysis.

Proc format library=work;

value $CommunityA

'Community A' = 'Community A'

'Community B' = '1'

'Community C' = '2'

'Community D' = '3'

'Community E' = '4

;

value $CommunityB

'Community A' = '1'

Community B' = 'Community B'

Community C' = '2'

'Community D' = '3'

'Community E' = '4

;

run;

Then for any report procs use the appropriate format. If there are a large number of communities involved it is likely worth making a control data set for proc format.

Peter_C
Rhodochrosite | Level 12

If you are creating different physical files or datasets, then it is straightforward.

However, if you want the appearance of a common/shared dataset to depend on the reader of the dataset, then just ensure the formatsearch path for the user has the appropriate "blinding" format for that user/usergroup in the first format catalog named in the format search path option (FMTSEARCH)

NuPur20 seems to be requesting files.

If these are SAS datasets, my approach would be different from the "external files" solution.

UrvishShah
Fluorite | Level 6

Hi,

Try the following code in addition of Proc Format.....

data commA commB commC commD;

      set test;

      if community_name EQ "communityA" then output commA;

      if community_name NE "communityA" then do;

         community_name = _N_;

         output commA;

      end;

      if community_name EQ "communityB" then output commB;

      if community_name NE "communityB" then do;

         community_name = _N_;

         if _N_ = '2' then community_name = "communityB";

         output commB;

     end;

      if community_name EQ "communityC" then output commC;

      if community_name NE "communityC" then do;

         community_name = _N_;

         if _N_ = '3' then community_name = "communityC";

         output commC;

     end;

      if community_name EQ "communityD" then output commD;

      if community_name NE "communityD" then do;

         community_name = _N_;

         if _N_ = '4' then community_name = "communityD";

         output commD;

     end;

run;

If there is many community (say more than 50) then process the same logic with iterative %DO loop within Macro Definition...

Cheers

Ron_MacroMaven
Lapis Lazuli | Level 10

Here is a General Solution, section 3.3:

http://www.sascommunity.org/wiki/Macro_CallText

Ron Fehd  macro maven

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 2618 views
  • 0 likes
  • 5 in conversation